c++ - linux linking to a .so , but still getting undefined reference -


i trying create executable uses code both static libraries , shared library:

the static libs several boost .a , pthread , libbus.a. shared lib libwrap.so.

note libwrap , uses code libbus , libbus uses code pthread. finally, executable uses code libwrap , boost.

since order of libraries included in linker matters trying find "winning" sequence.

the linking stage following (pasted in multiple lines convenience):

$ /usr/bin/c++         -wall -wextra      -fpic      -fvisibility=hidden -fno-strict-aliasing -wno-long-long      -m64      -rdynamic      -d_unicode -dunicode       cmakefiles/wrapper_test.dir/test.cpp.o      /usr/local/lib/libboost_log.a       /usr/local/lib/libboost_system.a      /usr/local/lib/libboost_filesystem.a      /usr/local/lib/libboost_date_time.a      /usr/local/lib/libboost_thread.a      /usr/local/lib/libboost_log_setup.a      /usr/local/lib/libboost_chrono.a      -pthread       /home/nass/dev/data_parser/trunk/external/lib/linux64_gcc_release/libbus.a        -l/home/nass/dev/data_parser_build/lib                    #this libwrap.so located     -wl,-rpath,/home/nass/dev/data_parser_build/lib      -lwrap                                                    #the shared lib       -o ../../../bin/wrapper_test 

the link error

cmakefiles/wrapper_test.dir/test.cpp.o: in function `main': test.cpp:(.text+0x2e): undefined reference `wrappernamespace::getwrapper()' collect2: error: ld returned 1 exit status 

the getwrapper() located in libwrap.so of course, , can verify symbol can found in there:

$ nm -ca ../../../lib/libwrap.so | grep getwrapper   00000000000423d6 t wrappernamespace::getwrapper() 

however, linker cannot find it. doing wrong here?

edit:

the linking command above generated following cmakelists.txt file:

set(target_name wrapper_test)  #set(cmake_binary_dir       ${cmake_source_dir}/bin) #set(executable_output_path ${cmake_binary_dir}) #set(library_output_path    ${cmake_binary_dir})  # include internal folder include_directories(${cmake_source_dir}/include/wrapper)   add_executable(${target_name} test.cpp)  add_boost_lib(${target_name} log system filesystem date_time thread log_setup chrono) setup_libbus(${target_name})    #the libbus.a target_link_libraries(${target_name} -l../../../lib -lwrap)  set_property(target ${target_name} property folder test) 

i start looking @ cmake file generates these lines.

it should simple add shared libaries path, example:

find_library(         libwrapper         names wrap         paths /home/nass/dev/data_parser_build/lib ) 

and link them test file, example

add_executable(test src/test.cpp) target_link_libraries(test ${libwrapper}) 

similar should work static libraries. has advantage don't have deal compiler/platform specific details cmake supposedly handles you, , can complex & obscure.

if library generated dynamically, i.e. before cmake configuration time, pass appropriate linking flags target_link_libraries:

target_link_libraries(test -l/home/nass/dev/data_parser_build/lib -lwrap) 

i have used suggestion in few projects (e.g. https://github.com/caskorg/cask/blob/master/cmakelists.txt) dynamically generate library, link against it. if doesn't work suspect else wrong.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -