1

I downloaded the last version of Conan from here and then I've done the following.

  1. Creating a new c++ project with the following code

main.cpp

 #include "Poco/MD5Engine.h"
 #include "Poco/DigestStream.h"

 #include <iostream>

 int main(int argc, char** argv)
 {
     Poco::MD5Engine md5;
     Poco::DigestOutputStream ds(md5);
     ds << "abcdefghijklmnopqrstuvwxyz";
     ds.close();
     std::cout << Poco::DigestEngine::digestToHex(md5.digest()) << std::endl;
     return 0;
 }

CMakeList.txt

cmake_minimum_required(VERSION 3.25)
project(TestMailPrj)

set(CMAKE_CXX_STANDARD 20)

find_package(poco REQUIRED)

add_executable(TestMailPrj main.cpp)
target_link_libraries(${PROJECT_NAME} POCO)

conanfile.txt

[requires]
cmake/3.25.3
poco/1.12.4

[generators]
CMakeDeps
CMakeToolchain
  1. Run the following command: conan install . --output-folder=build --build=missing

Now, even if my all dependencies were installed properly, in CMakeFile it can not find my Poco library.

By not providing "Findpoco.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "poco", but CMake did not find one.
Could not find a package configuration file provided by "poco" with any of the following names:
  pocoConfig.cmake
  poco-config.cmake
Add the installation prefix of "poco" to CMAKE_PREFIX_PATH or set "poco_DIR" to a directory containing one of the above files. If "poco" provides a separate development package or SDK, be sure it has been installed.

Dose anyone knows what exactly I am doing wrong or this is a bug?

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Mircea
  • 1,671
  • 7
  • 25
  • 41

1 Answers1

1

Your example is almost good to be built, but needs some updates:

The cmake package is tool requirement, not a regular build, as you will need to run cmake only when building your project, not for runtime. Thus, you need to update your conanfile.txt to:

[requires]
poco/1.12.4

[tool_requires]
cmake/3.25.3

[generators]
CMakeDeps
CMakeToolchain

Second, you CMakeLists.txt is looking for poco target, but Conan will generate FindPoco.cmake instead, so you need to update not only it, but also the target:

cmake_minimum_required(VERSION 3.25)
project(TestMailPrj CXX)

find_package(Poco REQUIRED Foundation Crypto CONFIG)

add_executable(TestMailPrj main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Poco::Foundation Poco::Crypto)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)

You really don't need C++20 here, C++11 is enough for your example, so I updated it. Plus, you are using MD5Engine and DigestStream that are part of Crypto module. The Foundation module is basic and always needed. You could use Poco::Poco module instead, it's generated by Conan and includes all modules.

Your installation command is correct:

conan install . --output-folder=build --build=missing

Now, we need to build the project:

$cd build/

$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
-- Using Conan toolchain: /tmp/example/build/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 17 with extensions OFF
-- The CXX compiler identification is AppleClang 14.0.3.14030022
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Component target declared 'Poco::Foundation'
-- Conan: Component target declared 'Poco::JSON'
-- Conan: Component target declared 'Poco::Net'
-- Conan: Component target declared 'Poco::Redis'
-- Conan: Component target declared 'Poco::XML'
-- Conan: Component target declared 'Poco::Crypto'
-- Conan: Component target declared 'Poco::Data'
-- Conan: Component target declared 'Poco::DataMySQL'
-- Conan: Component target declared 'Poco::DataPostgreSQL'
-- Conan: Component target declared 'Poco::DataSQLite'
-- Conan: Component target declared 'Poco::Encodings'
-- Conan: Component target declared 'Poco::JWT'
-- Conan: Component target declared 'Poco::MongoDB'
-- Conan: Component target declared 'Poco::Util'
-- Conan: Component target declared 'Poco::Zip'
-- Conan: Component target declared 'Poco::ActiveRecord'
-- Conan: Component target declared 'Poco::NetSSL'
-- Conan: Target declared 'Poco::Poco'
-- Conan: Component target declared 'PCRE2::8BIT'
-- Conan: Component target declared 'PCRE2::POSIX'
-- Conan: Component target declared 'PCRE2::16BIT'
-- Conan: Component target declared 'PCRE2::32BIT'
-- Conan: Target declared 'pcre2::pcre2'
-- Conan: Target declared 'BZip2::BZip2'
-- Conan: Including build module from '/Users/conan/.conan2/p/bzip2da06f0ccd4faa/p/lib/cmake/conan-official-bzip2-variables.cmake'
-- Conan: Target declared 'ZLIB::ZLIB'
-- Conan: Target declared 'expat::expat'
-- Conan: Component target declared 'SQLite::SQLite3'
-- Conan: Component target declared 'libpq::pgport'
-- Conan: Component target declared 'libpq::pgcommon'
-- Conan: Component target declared 'libpq::pq'
-- Conan: Target declared 'PostgreSQL::PostgreSQL'
-- Conan: Target declared 'libmysqlclient::libmysqlclient'
-- Conan: Component target declared 'OpenSSL::Crypto'
-- Conan: Component target declared 'OpenSSL::SSL'
-- Conan: Target declared 'openssl::openssl'
-- Conan: Including build module from '/Users/conan/.conan2/p/opens33d41aee1f477/p/lib/cmake/conan-official-openssl-variables.cmake'
-- Conan: Component target declared 'zstd::libzstd_static'
-- Conan: Target declared 'LZ4::lz4_static'
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/example/build

$ cmake --build .
[ 50%] Building CXX object CMakeFiles/TestMailPrj.dir/main.cpp.o
[100%] Linking CXX executable TestMailPrj
[100%] Built target TestMailPrj


$ ./TestMailPrj 
c3fcd3d76192e4007dfb496cca67e13b

It's important to note two things here:

  • The CMake build type must be equals as your Conan profile, by default CMake builds on Debug, but Conan uses Release by default, so you need to be explicit.
  • The CMake toolchain file is mandatory, otherwise, your project will not find Poco and will not comsume compiler flags imported from your Conan profile.

For further learning, I recommend you reading the Build a simple CMake project using Conan tutorial.

uilianries
  • 3,363
  • 15
  • 28
  • I've followed all of your steps and it runs the CMake properly with success, but when I run the "cmake --build ." I get the fallowing error – Mircea Apr 26 '23 at 16:43
  • /usr/bin/ld: CMakeFiles/TestMailPrj.dir/main.cpp.o: in function `main': main.cpp:(.text.startup+0x13c): undefined reference to `Poco::Net::MailMessage::MailMessage(Poco::Net::PartStoreFactory*)' /usr/bin/ld: main.cpp:(.text.startup+0x163): undefined reference to `Poco::Net::MailMessage::setSender(std::__cxx11::basic_string, std::allocator > const&)' – Mircea Apr 26 '23 at 16:43
  • /usr/bin/ld: main.cpp:(.text.startup+0x1a9): undefined reference to `Poco::Net::MailRecipient::MailRecipient(Poco::Net::MailRecipient::RecipientType, std::__cxx11::basic_string, std::allocator > const&)' /usr/bin/ld: main.cpp:(.text.startup+0x1b4): undefined reference to `Poco::Net::MailMessage::addRecipient(Poco::Net::MailRecipient const&)' /usr/bin/ld: main.cpp:(.text.startup+0x1bc): undefined reference to `Poco::Net::MailRecipient::~MailRecipient()' – Mircea Apr 26 '23 at 16:43
  • /usr/bin/ld: main.cpp:(.text.startup+0x1f6): undefined reference to `Poco::Net::MailMessage::setSubject(std::__cxx11::basic_string, std::allocator > const&)' /usr/bin/ld: main.cpp:(.text.startup+0x232): undefined reference to `Poco::Net::MailMessage::setContent(std::__cxx11::basic_string, std::allocator > const&, Poco::Net::MailMessage::ContentTransferEncoding)' /usr/bin/ld: main.cpp:(.text.startup+0x254): undefined reference to `Poco::Net::MailMessage::~MailMessage()' – Mircea Apr 26 '23 at 16:44
  • /usr/bin/ld: CMakeFiles/TestMailPrj.dir/main.cpp.o: in function `main.cold': main.cpp:(.text.unlikely+0x10): undefined reference to `Poco::Net::MailMessage::~MailMessage()' /usr/bin/ld: main.cpp:(.text.unlikely+0x30): undefined reference to `Poco::Net::MailRecipient::~MailRecipient()' collect2: error: ld returned 1 exit status gmake[2]: *** [CMakeFiles/TestMailPrj.dir/build.make:107: TestMailPrj] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/TestMailPrj.dir/all] Error 2 gmake: *** [Makefile:91: all] Error 2 – Mircea Apr 26 '23 at 16:44
  • sorry for so many comments, I couldn't put the whole error in one comment. Also another interesting this is that, even if my libs are seen as there should be by CMake, they are not CLion. Should I add something into the CMakeList to make that path for poco and other libs visible for CLion? – Mircea Apr 26 '23 at 16:46
  • In that case, you need to use `conan install . --output-folder=build --build=missing -s compiler.libcxx=libstdc++11`. Your CMake is configured to use new abi, but your profile does not. It's also recommended that you update your profile too, you will need to write directly in the file, usually located at `~/.conan2/profiles/default` than you need to replace `libstdc++` by `libstdc++11`. More info: https://docs.conan.io/2/reference/config_files/settings.html#c-standard-libraries-aka-compiler-libcxx – uilianries Apr 26 '23 at 17:54
  • after I've did this, I have the fallowing error: /home/vdumitru/CLionProjects/TestMailPrj/main.cpp:1:10: fatal error: Poco/MD5Engine.h: No such file or directory 1 | #include "Poco/MD5Engine.h" – Mircea Apr 26 '23 at 20:09
  • Not finding the header should be solved by pointing the toolchain cmake file. I would recommend you removing the build folder and try a fresh conan install + cmake commands. Plus, check if the definition CMAKE_TOOLCHAIN_FILE is correct and points to an existing file (generated by Conan). – uilianries Apr 27 '23 at 08:38
  • I see, thanks a lot for your help, I've made it work now :D – Mircea Apr 27 '23 at 11:51
  • Nice, glad for helping! :D – uilianries Apr 27 '23 at 14:48
  • In the answer, @uilianries says that cmake should be in the [tool_requires] section, not the [requires] section. But in his updated conanfile.txt, he moved the poco package to the [tool_requires] section instead of moving the cmake package. – Tim Crews May 12 '23 at 13:56
  • @TimCrews well observed! I just fixed it now. Thanks! – uilianries May 14 '23 at 10:48