pocoproject / conan-poco

Conan.io package for POCO C++ Libraries
17 stars 28 forks source link

Unable to link against Poco::JWT #64

Closed rmkerr closed 4 years ago

rmkerr commented 4 years ago

I'm unable to use the Poco::JWT library, despite enabling it. I'm a beginner to Poco and Conan, so I may just be doing something dumb. Every time I build, I get an undefined reference to Poco::JWT::Signer::Signer error from the linker.

To repro:

1) Start with from the conan MD5 examples:

git clone https://github.com/conan-io/examples.git && cd examples/libraries/poco/md5

2) Edit conanfile.txt to use the latest version of Poco, and to enable JWT library support:

[requires]
poco/1.10.1

[options]
poco:enable_jwt=True

[generators]
cmake

3) Run a successful build, without a dependency on the Poco::JWT library:

mkdir build && cd build
conan install ..
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
cmake --build .

4) Add a dependency on the Poco::JWT library by replacing the contents of md5.cpp:

#include "Poco/JWT/Signer.h"

int main(int argc, char** argv)
{
    Poco::JWT::Signer signer("0123456789ABCDEF0123456789ABCDEF");
    return 0;
}

5) Repeat the build process, and observe the following error:

Scanning dependencies of target md5
[ 50%] Building CXX object CMakeFiles/md5.dir/md5.cpp.o
[100%] Linking CXX executable bin/md5
CMakeFiles/md5.dir/md5.cpp.o: In function `main':
md5.cpp:(.text.startup+0x8f): undefined reference to `Poco::JWT::Signer::Signer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
md5.cpp:(.text.startup+0xad): undefined reference to `Poco::JWT::Signer::~Signer()'
collect2: error: ld returned 1 exit status
CMakeFiles/md5.dir/build.make:94: recipe for target 'bin/md5' failed
make[2]: *** [bin/md5] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/md5.dir/all' failed
make[1]: *** [CMakeFiles/md5.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

If anyone can point me in the right direction (and the solution is simple enough for a beginner), I'd be happy to put up a PR with the fix.

rmkerr commented 4 years ago

@obiltschnig Does this repro look like an actual issue to you?

obiltschnig commented 4 years ago

I'd say you also have to link the PocoJWT library (and its dependencies PocoCrypto and PocoJSON) in the CMakeLists.txt.

rmkerr commented 4 years ago

Thanks, that was all it took. For anyone who runs into this issue in the future, I fixed it by editing the target_link_libraries in my CMakeLists.txt:

target_link_libraries(webserver ${CONAN_LIBS} PocoJWT PocoCrypto PocoJSON)