User forums > Using Code::Blocks

undefined reference to shared library from shared library

(1/3) > >>

MyMindsAvatar:
Hi folks,

I'm having trouble compiling a project of mine and I'm not sure exactly where the problem lies. I suspect I haven't enabled/disabled something in the C::B IDE, but am at a complete loss as to exactly what that might be. Apologies for the slightly complicated title, but my problem is slightly complicated...

My situation is that I'm writing a shared library (say, library A) that links to another shared library (library B). I've got these two library projects and a MainApp project in a single workspace, with project dependencies: MainApp depends on library A, library A depends on library B. Both libraries build ok and in any order (i.e. library B builds ok on it's own, and library A also builds ok after building library B), but when I try to build MainApp I am hit with undefined reference errors on library A.

I have placed the reference to library B in the Link Settings -> Link Libraries for library A, and similarly the reference to library A for MainApp. I expected library A to implicitly use library B because of its link settings, but (on reading a post online: http://gcc.gnu.org/ml/gcc-help/2008-07/msg00266.html) when running "ldd" on the library A file to list the dependencies, I don't see library B listed.

Build log for library B (Images):
g++ -shared -L/home/richard/programming/wxWidgets-2.9.4/mybuild/lib  obj/Debug/src/StatusGridCellRendererBitmaps.o obj/Debug/src/ItemsPanelBitmaps.o   -o bin/Debug/libImages.so -L/usr/local/lib -pthread   -lwx_gtk2u-2.9

Build log for library A (RunSamplesWorkspace):
g++ -shared -L../Images/bin/Debug -L/home/richard/programming/wxWidgets-2.9.4/mybuild/lib  obj/Debug/src/TableArrangement.o obj/Debug/src/StatusGridCellRenderer.o obj/Debug/src/ItemExecutable.o obj/Debug/src/ItemsPanel.o obj/Debug/src/RunlistPanel.o   -o bin/Debug/libRunSamplesWorkspace.so -L/usr/local/lib -pthread   -lwx_gtk2u-2.9    -lImages

Build log for MainApp (MainApp):
g++ -L../RunSamplesWorkspace/bin/Debug -L/home/richard/programming/wxWidgets-2.9.4/mybuild/lib  -o bin/Debug/MainApp obj/Debug/src/App.o   -L/usr/local/lib -pthread   -lwx_gtk2u-2.9    -lRunSamplesWorkspace
../RunSamplesWorkspace/bin/Debug/libRunSamplesWorkspace.so: undefined reference to `RunSamples::GetDeleteBitmap()'
     (message repeated for all namespace functions included, but are all defined in the library B implementation files)


Please help. What have I missed or done wrong? Any and all advice is most welcome, and please request any extra information as you need. Or, indeed, if this is the wrong forum to ask this question (is it compiler/linker related?), then please forgive me but please tell me so I can go to their forums and try again.

Thanks in advance.

Richard ~

Ubuntu 12.10, Code::Blocks svn (pasgui, precise package), gcc 4.7.2

stahta01:
Wrong forum/website; if you have undefined references it is a Linking problem.

Why do you NOT add "Images" library to library list.

Tim S.



MyMindsAvatar:
Thanks, I knew it had to be a linking problem (I still relatively new to C++ programming), but I had linked the libraries through the Linker Settings under Build Options (hence my first thought that I'd done something wrong in C::B). I thought this would work (it works when linking library A to MainApp). Is this the library list you mentioned? I've tried linking to library B from both library A and MainApp but that doesn't work (same messages as before anyway). If there's nothing I've done wrong from a C::B perspective then I will move to a linking forum with thanks.

Richard ~

stahta01:
I suggest reading all of the FAQ in the future. http://wiki.codeblocks.org/index.php?title=FAQ

Read at least these two.

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_My_build_fails_with_multiple_undefined_reference_errors.3F

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F

Also, suggest looking at this page when you have questions.

http://wiki.codeblocks.org/index.php?title=User_documentation

Tim S.

MyMindsAvatar:
Thanks for those links. I've pored through these help files and from what I can make out, I have done everything correctly from a C::B perspective. I strongly suspect (as you mentioned earlier) a linking problem. The ldd output for my library A didn't include library B, which it should have done, so there must be something wrong with the library building/linking.

Thanks for your help. I feel quite confident that I've done things correctly in C::B now. Just gotta source the linking problem.

All the best,

Richard ~

Navigation

[0] Message Index

[#] Next page

Go to full version