pr0g/cmake-examples

shared library example met build error

Closed this issue · 2 comments

I try a few times to build core/shared/application. The following error occurs. The detailed log as follows

user@user-AIOT-AIVD:~/cmake-examples/examples/core/shared/application$ cmake --build build
Checking file [/home/user/cmake-examples/examples/core/shared/library/install/lib/cmake/calculator-shared/calculator-sharedConfig.cmake]
Checking file [/home/user/cmake-examples/examples/core/shared/library/install/lib/cmake/calculator-shared/calculator-shared-config.cmake]
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/cmake-examples/examples/core/shared/application/build
Scanning dependencies of target calculator-app
[ 50%] Building CXX object CMakeFiles/calculator-app.dir/main.cpp.o
[100%] Linking CXX executable calculator-app
/usr/bin/ld: CMakeFiles/calculator-app.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x1e): undefined reference to `calc_pow'
/usr/bin/ld: calculator-app: hidden symbol `calc_pow' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/calculator-app.dir/build.make:85: calculator-app] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/calculator-app.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

pr0g commented

Hey @HomeLH,

Hmm that's a weird one, it looks like the install went okay and the headers were found, but when trying to link, the definition of calc_pow isn't found.

It might be a visibility thing as it's a shared library. On Windows there's the dll_import/export stuff that's hidden behind a define, but it looks like you're on Linux? The default there afaik is everything is public (not hidden) but perhaps something in your setup is different.

As a quick test you could try adding __attribute__ ((visibility ("default"))) to the declaration of calc_pow. This page has more info too - https://gcc.gnu.org/wiki/Visibility.

Can I ask what platform you're on and what compiler you're using? Also can you try running the build command with -v to get more output?

Thanks!

Tom

pr0g commented

Closing for now due to inactivity