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

  • Home
  • SEARCH
  • 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 4271432
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:26:29+00:00 2026-05-21T07:26:29+00:00

Additional Questions added below, 4/11/2011 I am developing a cross-platform set of shared libraries

  • 0

Additional Questions added below, 4/11/2011

I am developing a cross-platform set of shared libraries DLLs/Sos and tester programs in C++ though I have to be able to support C. The libraries will ship as object code only, but the tester program(s) will ship with source so our customers can have example code. For this reason I am designing the libraries to be loaded at runtime, i.e. dynamic linking using dlopen()/LoadLibraryA().

I am using g++ 4.4.3-4 on Umbutu 10.04 and VC++ 2008 on Vista/64 (in 32 bit mode).

Everything seems to work just fine on Windows (right now). However, when I compile on Linux I am getting some errors I can’t figure out.

The tester and the library have several classes coded in several .cpp’s and .h’s. The classes and most everything in the library except the main entry points are in a namespace DISCOVER_NS.

Here is a brief sketch of the project:

First, an admission, I’ve shortened a bunch of names so the code is more readable.

discover.cpp

  • Creates a class object with a pointer to it called theMainObject of type DiscoverObject.

  • Has an extern “C” function that returns theMainObject to the caller program as void*.

  • DiscoverObject has several methods and instantiates other classes found in separate cpp’s and .h’s. One particular method is named Hello(), which does what you’d expect, it prints a “hello” test message..


tester.cpp

  • Gets a handle to the library

  • gets the function pointer to the function that returns theMainObject.

  • Executes the function (pointer) and casts the returned address from void* to DISCOVER_NS::DiscoverObject* aDiscoverObject.

  • Run aDiscoverObject->Hello().


I compile with:

CC = @g++

gflags = -g3

cflags = -fPIC -Wall -pedantic

lib_linkflags := -shared -fPIC -lstdc++ -lrt -lpthread -rdynamic

tester_linkflags := -ldl -lpthread

defines = -D_linux_ -D_DEBUG -D_IPC_ARCH_INTEL=1 -D_THREAD_SAFE


Now, when I compile I get these errors:
*Tester.cpp:142: undefined reference to `Discover_NS::DiscoverObject::hello()’*

I also get a bunch of other undefined reference errors from discover.so saying, for example:
*discover.so: undefined reference to `Discover_NS::DeviceList::~DeviceList()*


I have tried making virtually everything in the SO extern “C”. No difference.

I tried putting statements into discover.cpp that look like:
extern void Discover_NS::OtherClass::method( args );
but that gives me errors about” declaration outside of class is not deffinition” errors.


I know it will help to see code, but I need time to whack out something small for posting.

Can anyone offer ideas to solve this mess?

Thanks,

Wes

Dmitry’s solution was not quite all of the fix, but was a necessary element in the solution. Upon examination of my makefile I found a couple of unintentionally duplicated lines, which I removed, and two “typos” where I had the wrong path for -o’s coded into compile steps. The broken steps compiled logger.cpp and RemException.cpp:

./common/logger.o : ./common/logger.cpp
    $(CC) $(gflags)  $(cflags) -c  $(defines)  -I ./common  
        -I ./EdgeIO  -I ./Discover   
        -o ./common/Debug/logger.o   <+++++++++ path to .o was wrong
        ./common/logger.cpp   2>&1  | tee ./RemKonTester/logger.ERR

Then I found the real bug. I completely missed the fact that I wasn’t compiling all of my .cpp’s in the Discover directory!. It took a good hour to get all the nit-pics removed but now she comiles from a makefile just fine.

NEW VERSION OF THE ORIGINAL QUESTION: NOw that I know it WILL work via makefile, how do I talk Eclipse into doing the same thing the makefile is doing?

Thanks Dmitry.

Wes

Well, my problem is still here.

I have my code compiling with Dmitry’s (@Dmitry) suggestions in place. Only, they appear to be causing a separate problem. I want my libraries to link to he main test program dynamically, at run time. Adding the -l Discover -l EdgeIO to the link gets everything to compile, but it give me static linking.

FYI, The unused “pi”s are so the SO has a floating point number in it and will thus compile with floating point support. Required if caller ever wants to use floating point numbers. Anybody got a better way to force g++ to comkpile with floating point included?

After fixing the many bugs Dmitry helped me find, I now get this output:

make
./Discover/dllmain.cpp: In function ‘void InitalizeLibraryServices()’:
./Discover/dllmain.cpp:175: warning: unused variable ‘pi’


./EdgeIO/dllMain.cpp: In function ‘void InitalizeLibraryServices()’:
./EdgeIO/dllMain.cpp:158: warning: unused variable ‘pi’


linking RemKonTester
    gflags = -g3
    tstlinkflags = -ldl  -lpthread 
    defines =  -D__linux__   -D_DEBUG   -D_IPC_ARCH_INTEL=1   -D_THREAD_SAFE

./RemKonTester/Debug/RemKonTester.o: In function `main':
/home/wmiller/Projects/Eclipse/./RemKonTester/RemKonTester.cpp:81: undefined 
    reference to `RemKon_EdgeIO::EdgeIoObject::hello()'
/home/wmiller/Projects/Eclipse/./RemKonTester/RemKonTester.cpp:111: undefined 
    reference to `RemKon_Discover::DiscoverObject::hello()'
/home/wmiller/Projects/Eclipse/./RemKonTester/RemKonTester.cpp:116: undefined 
    reference to `RemKon_Discover::DiscoverObject::SetLogLevel(unsigned int)'
/home/wmiller/Projects/Eclipse/./RemKonTester/RemKonTester.cpp:117: undefined 
    reference to `RemKon_Discover::DiscoverObject::hello()'
/home/wmiller/Projects/Eclipse/./RemKonTester/RemKonTester.cpp:118: undefined 
    reference to `RemKon_Discover::DiscoverObject::LocalIpAddress(int)'
/home/wmiller/Projects/Eclipse/./RemKonTester/RemKonTester.cpp:122: undefined 
    reference to `RemKon_Discover::DiscoverObject::RegisterCallback(bool(*)
    (void*), void*)'
/home/wmiller/Projects/Eclipse/./RemKonTester/RemKonTester.cpp:123: undefined 
    reference to `RemKon_Discover::DiscoverObject::Search()'

collect2: ld returned 1 exit status

I get the same set of error messages from Eclipse.

RemKonTester.cpp includes all the .h’s where these items are declared. I have tried them with the declarations extern “C” and not.

Hoping for help,

Wes

  • 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-21T07:26:30+00:00Added an answer on May 21, 2026 at 7:26 am

    Your problem seems to be the position of -l<library>:

    $(CC)  $(gflags)  $(tstlinkflags) $(defines)      -L ./Debug    -ldiscover   
            -ledgeio -o ./Debug/RemKonTester  ./RemKonTester/Debug/RemKonTester.o  
            ./RemKonTester/Debug/logger.o  ./RemKonTester/Debug/libraryClass.o   
            2>&1  | tee ./RemKonTester/make.ERR
    

    They should be after the object files, because the linker loads them when they’re met at the command line and search for the undefined symbols.

    See man ld (specifically -l option) for more info:

    -l namespec

    …

    The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a
    symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the
    appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause
    the linker to search the archive again.

    This should work for you:

    $(CC) $(gflags) $(tstlinkflags) $(defines) -L ./Debug -o ./Debug/RemKonTester ./RemKonTester/Debug/RemKonTester.o ./RemKonTester/Debug/logger.o ./RemKonTester/Debug/libraryClass.o -ldiscover -ledgeio 2>&1 | tee ./RemKonTester/make.ERR

    P.S. Note that there an option for editing your question in StackOverflow, posting additional info as an answer is not a good practice.

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

Sidebar

Related Questions

After following the advice in this question successfully, I added a couple additional lines
Is there some additional configuration needed before I can set thread priorities in a
My questions are divided into three parts Question 1 Consider the below code, #include
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record
I need to display additional information, like a tooltip, but it's a lot of
how do I pass additional information to the service method returning the collection of
are there any additional WPF themes from microsoft except that default ones provided in
I'm storing some additional per-user information using the AUTH_PROFILE_MODULE . We can access the
What is the best approach to define additional data for typedef enums in C?
I'm using jQuery to add an additional row to a table as the last

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.