Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3939600
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:19:08+00:00 2026-05-20T00:19:08+00:00

I am trying to build a very simple C++ program using the Maven NAR

  • 0

I am trying to build a very simple C++ program using the Maven NAR plugin. I’ve set up a Maven module for building a shared library, and another for linking in the library and building an executable that uses it. Building on a Mac works great and I can run the program. Unfortunately, building on Windows (XP) with MS Visual C++ (free version) fails with a linker error. The only difference in configurations between the two machines (other than OS and compiler) is that I run vcvars32.bat before building with Maven on the Windows machine. Here’s the error I am getting:

main.obj : error LNK2019: unresolved external symbol "public: int __thiscall 
Calculator::add(int,int)" (?add@Calculator@@QAEHHH@Z) referenced in function
_main executable.exe : fatal error LNK1120: 1 unresolved externals

The linker command spit out by the NAR plugin looks like this:

link /MANIFEST /NOLOGO /SUBSYSTEM:CONSOLE /INCREMENTAL:NO /OUT:executable.exe
C:\dev\Projects\trunk\executable\target\nar\obj\x86-Windows-msvc\main.obj

I expect it should have the DLL generated by my shared library module listed, but its not there. The DLL’s NAR is unpacked in the executable’s target directory, as it should be.

Any help in configuring the NAR plugin for Windows would be appreciated. Alternately a command line showing how to properly execute the linker would be useful so I can backfill the NAR configuration to achieve it. Thanks.

My shared library module:

Calculator.h

#ifndef CALCULATOR_H
#define CALCULATOR_H

class Calculator {
public:
    int add(int first, int second);
};

#endif

Calculator.cc

#include "Calculator.h"

int Calculator::add(int first, int second) {
    return first + second;
}

pom.xml (snippets):

<groupId>com.mycompany</groupId>
<artifactId>library</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>nar</packaging>

...

<plugin>
    <artifactId>maven-nar-plugin</artifactId>
    <version>2.1-SNAPSHOT</version>
    <extensions>true</extensions>
    <configuration>
        <libraries>
            <library>
                <type>shared</type>
            </library>
        </libraries>
    </configuration>
</plugin>

My executable module:

main.cc

#include <iostream>
#include "Calculator.h"

int main() {
    Calculator calculator;
    std::cout << calculator.add(2, 5) << std::endl;
}

pom.xml (snippets)

<groupId>com.mycompany</groupId>
<artifactId>executable</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>nar</packaging>

<dependency>
    <groupId>com.mycompany</groupId>
    <artifactId>library</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <type>nar</type>
</dependency>

...

<plugin>
    <artifactId>maven-nar-plugin</artifactId>
    <version>2.1-SNAPSHOT</version>
    <extensions>true</extensions>
    <configuration>
        <libraries>
            <library>
                <type>executable</type>
            </library>
        </libraries>
    </configuration>
</plugin>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:19:08+00:00Added an answer on May 20, 2026 at 12:19 am

    Answering my own question.

    A colleague of mine dug into the murkier recesses of his brain and said he recalled something like “dicklespeck” being needed. That sounded bizarre so I put it in the “if all else fails I’ll look that up” bucket. After all else failed, I came back to it and Googled various spellings which revealed that he was correct. If I add this abomination to my class declaration:

    __declspec(dllexport)
    

    The DLL successfully links with the executable.

    So “fixing” the Calculator header file like so is the solution:

    #ifndef CALCULATOR_H
    #define CALCULATOR_H
    
    class __declspec(dllexport) Calculator {
    public:
        int add(int first, int second);
    };
    
    #endif
    

    Yuck! I can #define that thing away for non-windows builds, but still – yuck!

    Someone please tell me this isn’t the only solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a very simple c++ program in eclipse and I'm getting
I'm trying to build a very, very simple micro-webapp which I suspect will be
I built a (very simple) library, which I can call just fine from another
I'm getting the following error when trying to build my very simple webservice project.
I'm trying to build a very simple VPS control panel; i have the following
I'm trying to build a very simple sinatra app deployed on heroku. our app
I'm trying to compile a very simple program that makes a connection to a
I am trying to build a very simple driver. Its sole purpose will be
I am trying to build a very simple java project in Eclipse SDK Version:
I am playing around with ActionScript 3 and trying to build a very simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.