oatpp / example-crud

A complete example of a "CRUD" service (UserService) built with Oat++.

Home Page:https://oatpp.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linking of "crud-test" fails on Linux

mouse07410 opened this issue · comments

commented

Ubuntu-20.04 and Centos-8.

$ cmake .. -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/opt/local
-- The C compiler identification is GNU 8.5.0
-- The CXX compiler identification is GNU 8.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SQLite3: /usr/include (found version "3.26.0") 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ur20980/src/oatpp-example-crud/build
$ make -j all
[ 12%] Building CXX object CMakeFiles/crud-lib.dir/src/service/UserService.cpp.o
[ 25%] Building CXX object CMakeFiles/crud-lib.dir/src/ErrorHandler.cpp.o
[ 37%] Linking CXX shared library libcrud-lib.so
[ 37%] Built target crud-lib
[ 50%] Building CXX object CMakeFiles/crud-test.dir/test/tests.cpp.o
[ 62%] Building CXX object CMakeFiles/crud-test.dir/test/UserControllerTest.cpp.o
[ 75%] Building CXX object CMakeFiles/crud-exe.dir/src/App.cpp.o
[ 87%] Linking CXX executable crud-test
/usr/bin/ld: CMakeFiles/crud-test.dir/test/tests.cpp.o: undefined reference to symbol '_ZN5oatpp4test8UnitTest3runEi'
/opt/local/lib64/oatpp-1.3.0/liboatpp-test.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/crud-test.dir/build.make:118: crud-test] Error 1
make[1]: *** [CMakeFiles/Makefile2:113: CMakeFiles/crud-test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[100%] Linking CXX executable crud-exe
[100%] Built target crud-exe
make: *** [Makefile:101: all] Error 2

Fix (or a workaround for Linux, need guards for other OSes) is passing the following linker flag:

 export LDFLAGS="-Wl,--copy-dt-needed-entries"

I suggest adding the above to the CMakeLists.txt file, and/or to the README.md where you describe how to build it from the source.

Here's the author of this fix: https://zhangboyi.gitlab.io/post/2020-09-14-resolve-dso-missing-from-command-line-error/ and https://stackoverflow.com/questions/19901934/libpthread-so-0-error-adding-symbols-dso-missing-from-command-line

commented

I'd appreciate some reaction to this report. Ideally - incorporating the proposed fix. Minimally - just acknowledge.

Hello @mouse07410 ,

Thanks for the issue and for detailed description!

I'll try to reproduce the issue and after that we can apply the fix.

Regards,
Leonid