Poco libraries were installed using conan and cmake, IDE can go to the library code, but the linker has problems with it. The main causes of this problem checked, did not help. The library was installed by poco, must be appropriate.

#include <iostream> #include <Poco/Data/Session.h> #include <Poco/Data/MySQL/Connector.h> int main(){ Poco::Data::MySQL::Connector::registerConnector(); Poco::Data::Session session{"MySQL", "host=localhost;port=3306;db=statsDB;user=user;password=pass"}; return 0; } 

For SQLite, everything works fine, but if you change it in SQLite code to MySQL, make fails. Error text:

  CMakeFiles/ISPstats.dir/main.cpp.o: In function `main': main.cpp:(.text+0x13): undefined reference to `Poco::Data::MySQL::Connector::registerConnector()' main.cpp:(.text+0x128): undefined reference to `Poco::Data::Session::Session(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long)' main.cpp:(.text+0x155): undefined reference to `Poco::Data::Session::~Session()' clang: error: linker command failed with exit code 1 (use -v to see invocation) CMakeFiles/ISPstats.dir/build.make:94: recipe for target 'ISPstats' failed make[3]: *** [ISPstats] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/ISPstats.dir/all' failed make[2]: *** [CMakeFiles/ISPstats.dir/all] Error 2 CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/ISPstats.dir/rule' failed make[1]: *** [CMakeFiles/ISPstats.dir/rule] Error 2 Makefile:129: recipe for target 'ISPstats' failed make: *** [ISPstats] Error 2 

after applying the answer, @isnullxbh swears like this:

 CMakeFiles/ISPstats.dir/main.cpp.o: In function `main': /home/nerd/CLionProjects/ISPstats/main.cpp:6: undefined reference to `Poco::Data::MySQL::Connector::registerConnector()' clang: error: linker command failed with exit code 1 (use -v to see invocation) CMakeFiles/ISPstats.dir/build.make:83: recipe for target 'ISPstats' failed make[2]: *** [ISPstats] Error 1 CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/ISPstats.dir/all' failed make[1]: *** [CMakeFiles/ISPstats.dir/all] Error 2 Makefile:94: recipe for target 'all' failed make: *** [all] Error 2 

and the old way:

 /usr/bin/ld: cannot find -lPocoMongoDB /usr/bin/ld: cannot find -lPocoNet /usr/bin/ld: cannot find -lPocoNetSSL /usr/bin/ld: cannot find -lPocoCrypto /usr/bin/ld: cannot find -lPocoData /usr/bin/ld: cannot find -lPocoDataSQLite /usr/bin/ld: cannot find -lPocoZip /usr/bin/ld: cannot find -lPocoUtil /usr/bin/ld: cannot find -lPocoXML /usr/bin/ld: cannot find -lPocoJSON /usr/bin/ld: cannot find -lPocoFoundation clang: error: linker command failed with exit code 1 (use -v to see invocation) CMakeFiles/ISPstats.dir/build.make:94: recipe for target 'ISPstats' failed make[2]: *** [ISPstats] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/ISPstats.dir/all' failed make[1]: *** [CMakeFiles/ISPstats.dir/all] Error 2 Makefile:94: recipe for target 'all' failed make: *** [all] Error 2 
  • @VTT, I appeal to you, because you voted to close the question: the answer, the link to which is given at the beginning of the question, has nothing to do with this question - the author of the question himself understands what this is about, and he needs to help with this . Please review the question. I am writing here because I don’t know how to act in such cases, if this is done somehow inchae - sorry, I didn’t know. - isnullxbh

1 answer 1

After you run the command conan install ... , the source directory will conanbuildinfo.cmake file conanbuildinfo.cmake - and so, you need to connect it via the include in the cmake file, for example:

 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() 

Then specify the directories with installed libraries:

 target_link_directories(${PROJECT_NAME} PRIVATE ${CONAN_LIB_DIRS}) 

And link with them:

 target_link_libraries(${PROJECT_NAME} PRIVATE ${CONAN_LIBS}) 

UPD .:

Add the line to the options section:

 Poco:enable_data_mysql=True 

View a list of options here .

  • Comments are not intended for extended discussion; conversation moved to chat . - Yuriy SPb ♦