CMake with Conan cannot find assimp-vc142-mt.lib - c++

I'm trying to link assimp into a simple C++ project using Conan and CMake. However, when I build, it's giving me the following error:
LINK : fatal error LNK1104: cannot open file 'assimp-vc142-mt.lib' [C:\dev\test0\build\test.vcxproj]
Here is my conan default profile:
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.runtime=MD
compiler.version=16
build_type=Release
[options]
[build_requires]
[env]
I've made sure to use the same architecture for installing with Conan and building with CMake.
I've double checked that the library is installed.
I've installed other libraries (e.g. glfw) with no issues. Is this an issue with the Conan package, or am I missing something?

https://github.com/conan-io/conan-center-index/issues/7342
I had the CMake directives in the wrong order. You must do conan_basic_setup() before creating your executable and linking any libraries.

Related

Cross-compiling a Conan package

I'm writing a small C++ cross-platform library which uses CMake, Clang, Ninja and Conan. I've managed to cross-compile the library, but I'm having difficulties adding a Conan package. For a test, I've added fmt as a dependecy in conanfile like so:
conanfile.py
from conan import ConanFile
from conan.tools.cmake import CMakeDeps, CMakeToolchain
class App(ConanFile):
name = "example_library"
version = "1.0.0"
settings = "os", "compiler", "build_type", "arch"
requires = "fmt/9.0.0"
default_options = {"fmt:shared": True}
And I've made two conan profiles:
clanglinux
[settings]
os=Linux
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=clang
compiler.version=14
build_type=Release
[env]
CC=clang
CXX=clang++
CONAN_CMAKE_GENERATOR=Ninja
[conf]
tools.cmake.cmaketoolchain:generator=Ninja
[options]
[build_requires]
clangwindows
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=clang
compiler.version=14
build_type=Release
[env]
CC=clang
CXX=clang++
CONAN_CMAKE_GENERATOR=Ninja
[conf]
tools.cmake.cmaketoolchain:generator=Ninja
[options]
[build_requires]
When executing conan install for a native platform (in this case Windows) everything works as expected. However, when I try to cross-compile the dependency for Linux with conan install . --build=missing -pr:h=clanglinux -pr:b=clangwindows, I get the following error:
CMake Error at CMakeLists.txt:231 (add_library):
The install of the fmt target requires changing an RPATH from the build
tree, but this is not supported with the Ninja generator unless on an
ELF-based or XCOFF-based platform. The CMAKE_BUILD_WITH_INSTALL_RPATH
variable may be set to avoid this relinking step.
This error occurs after Conan's build() function get's called for the fmt package. It calls cmake with the following arguments:
cmake -G "Ninja"
-DCMAKE_TOOLCHAIN_FILE="C:/Users/name.surname/.conan/data/fmt/9.0.0/_/_/build/048e14dd7a94fe623d3253718843fce321999150/build/generators/conan_toolchain.cmake"
-DCMAKE_INSTALL_PREFIX="C:/Users/name.surname/.conan/data/fmt/9.0.0/_/_/package/048e14dd7a94fe623d3253718843fce321999150"
-DFMT_DOC="OFF"
-DFMT_TEST="OFF"
-DFMT_INSTALL="ON"
-DFMT_LIB_DIR="lib"
-DFMT_OS="ON"
-DCMAKE_POLICY_DEFAULT_CMP0091="NEW"
-DCMAKE_BUILD_TYPE="Release"
"C:\Users\name.surname\.conan\data\fmt\9.0.0\_\_\build\048e14dd7a94fe623d3253718843fce321999150\src"
As far as I know (correct me if I'm wrong), this command is specified in the fmt conanfile and I don't have a lot of control over it. But according to the error message, I should add -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON argument to the command. Is there a way to achieve this?
Also, why is it necessary to set CMAKE_BUILD_WITH_INSTALL_RPATH variable, can it be avoided altogether?
Thanks.

How to use conan to handle ImGui-SFML dependency in a cmake gcc project in Linux?

I want to handle the dependencies of a C++/cmake/gcc project in Linux using conan, and build an ImGui C++ demo as shown here: using imgui by Elias Daler
I have used conan to handle Boost dependencies successfully, but with ImGui-SFML I am having a linking error.
My conanfile.txt has the following instructions:
[requires]
imgui-sfml/2.1#bincrafters/stable
[imports]
bin, *.so -> ./bin
lib, *.a -> ./lib
[generators]
cmake_find_package
cmake_paths
cmake
And I added these lines to my CMakeLists.txt to work with conan:
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
link_directories(${CONAN_LIB_DIRS})
target_link_libraries(my_project ${CONAN_LIBS})
Then, inside build/ I run the following command to build the library and install the dependencies:
conan install .. --build imgui-sfml
So far so good with conan, the libImGui-SFML.a is generated (it is also copied to build/lib because of the [imports], though I think the copy shouldn't be required since I'm adding the link_directories() instruction).
Then, I generate the makefiles
cmake ..
Finally, when I try to build the project
cmake --build ./
I get these linking errors:
/usr/bin/ld: cannot find -lImGui-SFML
/usr/bin/ld: cannot find -lopenal
/usr/bin/ld: cannot find -lFLAC++
/usr/bin/ld: cannot find -lFLAC
The libs generated by conan are static:
libFLAC.a
libFLAC++.a
libfreetype.a
libImGui-SFML.a
libogg.a
libopenal.a
This post looks related, but didn't work for ImGui: Installing gtest with conan
Is the program looking for shared libraries?
Am I missing some configuration in the conanfile.txt or in the CMakeLists.txt file?
Edit:
Conan version 1.25.2
According to this reported issue, this solution for a similar question, and conan's basic setup documentation, in this case the CMakeLists.txt should include: adding the argument TARGET in the setup, and the call to conan_target_link_libraries instead of the usual target_link_libraries, as follows:
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
conan_target_link_libraries(${PROJECT_NAME})
So the conanfile.txt just needs these instructions:
[requires]
imgui-sfml/2.1#bincrafters/stable
[generators]
cmake

libz.so is missing when trying to build

I am building a project using cmake 3.5.1 and ninja on Ubuntu 16.04 server.
When I try to build I get an error about finding a zlib dependency..
ninja: error: '/usr/lib/libz.so' needed by 'MyProject', missing and no known rule to make it.
I have checked and confirmed I have zlib1g-dev package installed.
I assume the following line in cmake is what is looking for the libz.so
target_link_libraries(MyProject ${ZLIB_LIBRARIES})
The following line is present in the CMakeLists.txt
find_package(ZLIB REQUIRED)

sqlite do not link at compile time on windows

I met a weird problem. I can not link against sqlite3 lib (with a fresh installation of conan). I am trying to add sqlite3 to a project of mine that already contain a lot of boost code, but this the first time I met this kind of error.
int main(int argc, char *const argv[])
{
sqlite3 *dbb = NULL;
sqlite3_open("esrerer", &dbb);
}
This is the error message I receive :
main.cpp.obj : error LNK2019: unresolved external symbol_sqlite3_open referred in function main
I use conan for the lib :
[requires]
boost/1.71.0#conan/stable
sqlite3/3.29.0#bincrafters/stable
[generators]
cmake
And just in case, the content of my cmake:
cmake_minimum_required(VERSION 3.14)
project(project)
set(CMAKE_CXX_STANDARD 14)
include_directories(Server/include)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(sqlite3 REQUIRED)
add_executable(project Server/src/main.cpp)
target_link_libraries(project ${CONAN_LIBS})
EDIT : conan profile
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=16
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
You want to find SQLITE3 as CMake module but you need to consider two things:
The Conan package which provides sqlite3 has a cmake there? You can check it by looking into the package folder:
conan info --paths sqlite3/3.29.0#bincrafters/stable
ls /home/user/.conan/data/sqlite3/3.29.0/bincrafters/stable/package/6745b2c67ece017487d93454786f9082519559e7/
There is a Find CMake file there, but as you can see, it's camel cased and if you are running on Unix system, you know the file name is case sensitive. So you need to change your find_package statement:
find_package(SQLite3 REQUIRED)
Conan packages in general don't provide any CMake file, because Conan is able to generate them:
https://docs.conan.io/en/latest/integrations/build_system/cmake.html
So, in your case, you can use cmake_find_package + cmake:
[requires]
boost/1.71.0#conan/stable
sqlite3/3.29.0#bincrafters/stable
[generators]
cmake
cmake_find_package
The find cmake file generated will use the same name from the recipe:
Findsqlite3.cmake
Regards!

CMake Error: CMAKE_MODULE_PATH does not contain FindPoppler.cmake

my working platform is Ubuntu 18.04 LTS.
I'm trying to install QCViewer from github. It seems a lot of packages are needed from my installation of QCViewer from source. So, I worked on my way through the github repository, installed all the build dependencies at/usr, , and enter the folder QCViewer/build/release and run ./build. This worked fine untill the package "poppler" where cmake gives the following error:
root#ubuntu:/home/link/QCViewer-master/build/release# ./build
CMake Error at QCViewer/CMakeLists.txt:63 (FIND_PACKAGE):
By not providing "FindPoppler.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Poppler", but
CMake did not find one.
Could not find a package configuration file provided by "Poppler" with any
of the following names:
PopplerConfig.cmake
poppler-config.cmake
Add the installation prefix of "Poppler" to CMAKE_PREFIX_PATH or set
"Poppler_DIR" to a directory containing one of the above files. If
"Poppler" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "/home/link/QCViewer-master/build/release/CMakeFiles/CMakeOutput.log".
make: *** No rule to make target 'install'. Stop.
and also noted that:
link#ubuntu:~$ pkg-config --libs --cflags poppler
-I/usr/include/poppler -lpoppler
Meanwhile, I find that this project's CMakeLists.txtgiven as follows:
cmake_minimum_required (VERSION 2.6)
project(QCViewer)
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-2.4 freetype2 poppler-glib)
add_subdirectory(QCViewer)
so how can I fix it?