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!
Related
My goal is to write a simple, portable application using ImGUI. I also want a platform-agnostic build experience using cmake, and vcpkg to install dependencies. I got the program built and running on my Windows machine, but it's failing on my Macbook (macOS Monterey 12.6).
This is my vcpkg.json:
{
"name": "imguitest",
"version": "1.0",
"dependencies": [
"glad",
"glfw3",
{
"name": "imgui",
"features": [ "glfw-binding", "opengl3-binding" ]
}
]
}
This is my CMakeLists.txt:
cmake_minimum_required (VERSION 3.23)
project(ImGui-Test)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
add_executable(${PROJECT_NAME}
src/main.cpp
)
find_package(glad CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glad::glad)
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
find_package(imgui CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui)
find_package(OpenGL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL)
After running this:
# export VCPKG_DIR=/path/to/vcpkg/repo/
cmake -B ./build -S . "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
I get this error:
CMake Error at CMakeLists.txt:14 (find_package):
Could not find a package configuration file provided by "glad" with any of
the following names:
gladConfig.cmake
glad-config.cmake
Add the installation prefix of "glad" to CMAKE_PREFIX_PATH or set
"glad_DIR" to a directory containing one of the above files. If "glad"
provides a separate development package or SDK, be sure it has been
installed.
Do I have to manually install GLAD package myself and set the path? I thought vcpkg would handle that for me. Please let me know if I'm misunderstanding something, as I'm new to modern cmake and vcpkg.
This fixed it: brew install pkg-config
I got more descriptive error messages after I deleted the build folder. This error message was hidden when configuring cmake with vscode, but was visible when doing it through zsh terminal.
Building glfw3[core]:arm64-osx...
warning: -- Using community triplet arm64-osx. This triplet configuration is not guaranteed to succeed.
-- [COMMUNITY] Loading triplet configuration from: /Users/munta/Dev/vcpkg/triplets/community/arm64-osx.cmake
-- Downloading https://github.com/glfw/glfw/archive/7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz -> glfw-glfw-7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz...
-- Extracting source /Users/munta/Dev/vcpkg/downloads/glfw-glfw-7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz
-- Using source at /Users/munta/Dev/vcpkg/buildtrees/glfw3/src/172a7f6c9e-7678776297.clean
GLFW3 currently requires the following libraries from the system package manager:
xinerama
xcursor
xorg
libglu1-mesa
pkg-config
These can be installed via brew install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config
-- Configuring arm64-osx
-- Building arm64-osx-dbg
-- Building arm64-osx-rel
-- Fixing pkgconfig file: /Users/munta/Dev/vcpkg/packages/glfw3_arm64-osx/lib/pkgconfig/glfw3.pc
CMake Error at scripts/cmake/vcpkg_find_acquire_program.cmake:619 (message):
Could not find pkg-config. Please install it via your package manager:
brew install pkg-config
Call Stack (most recent call first):
scripts/cmake/vcpkg_fixup_pkgconfig.cmake:151 (vcpkg_find_acquire_program)
ports/glfw3/portfile.cmake:43 (vcpkg_fixup_pkgconfig)
scripts/ports.cmake:147 (include)
Preface: I am using Clion with Cygwin. I have installed vcpkg following their instructions. Then I followed restinio instructions to install restinio using vcpkg. Since restinio required fmt and http-parser I installed both of those too.
I have installed both the x86-windows version and x64-windows version of all 3 packages.
I linked vcpkg cmake file as per their instructions in Clion and have regenerated the CMakeCache
Currently I am trying to build specifically the x64-windows version (I was having other errors with the x86 version and I got further with the x64 version).
I have looked at this, and my initial error is different along with there is stuff inside of the directory that is in the relative path.
cmake_minimum_required(VERSION 3.23)
project(testing2)
set(CMAKE_CXX_STANDARD 14)
# RESTinio dependencies:
# 1. ASIO or Boost::ASIO (goes as headers, vcpkg knows where)
# 2. HTTP parser
find_package(unofficial-http-parser CONFIG REQUIRED)
# 3. fmtlib
find_package(fmt CONFIG REQUIRED)
# RESTinio itself
find_package(restinio CONFIG REQUIRED)
# Make your project dependent on restinio,
# and let cmake deal with all the headers paths and linked libs.
add_executable(testing2 main.cpp)
target_link_libraries(testing2 PRIVATE restinio::restinio)
cmake Options: -DCMAKE_TOOLCHAIN_FILE=C:\dev\vcpkg\vcpkg-master\scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET:STRING=x64-windows
Clion output in the cmake tab:
-- Configuring done
CMake Error in CMakeLists.txt:
Target "restinio::restinio" contains relative path in its
INTERFACE_INCLUDE_DIRECTORIES:
"C:/dev/vcpkg/vcpkg-master/installed/x64-windows/include"
CMake Error in CMakeLists.txt:
IMPORTED_LOCATION not set for imported target
"unofficial::http_parser::http_parser" configuration "Debug".
-- Generating done
CMake Error:
Running
'/cygdrive/c/Program Files/JetBrains/CLion 2021.2.3/bin/ninja/cygwin/ninja.exe' '-C' '/cygdrive/c/Users/Tally/Desktop/DevStuffs/Testing2/cmake-build-debug' '-t' 'recompact'
failed with:
ninja: error: build.ninja:35: loading 'CMakeFiles/rules.ninja': No such file or directory
include CMakeFiles/rules.ninja
^ near here
CMake Generate step failed. Build files cannot be regenerated correctly.
[Finished]
the path: "C:/dev/vcpkg/vcpkg-master/installed/x64-windows/include" exists and has asio, fmt, and restinio dirs along with asio.hpp and http_parser.h.
I have tried adding:
target_link_libraries(main PRIVATE unofficial::http_parser::http_parser) as vcpkg suggests when I install, but it gives me the same error just replaced restinio::restinio with unofficial::http_parser::http_parser.
I tried to use conan to integrate boost into my cpp Projekt.
While it seems conan does install the boost libraries, CMake says
-- Could NOT find Boost (missing: Boost_INCLUDE_DIR) (Required is at least version "1.78.0")
For the basic setup I tried to follow: https://codetrips.com/2020/03/20/1198/
And I found the question CMake not finding boost libraries from conan, but since the setup seems to be a bit different (and no solution was found), I would like to present my problem and project.
My project layout is:
- ${project_root}/CMakeLists.txt
- ${project_root}/conanfile.txt
- ${project_root}/main.cpp
- ${project_root}/build
With CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(boost_process_test)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
find_package(Boost 1.78.0)
add_executable(test main.cpp)
target_link_libraries(test PRIVATE Boost)
and with conanfile.txt
[requires]
boost/1.78.0
[generators]
cmake
and with main.cpp
#include <boost/process.hpp>
int main() {
return 0;
}
Within the build directory I called
$ conan install ..
yielding the output:
Configuration:
[settings]
...
build_type=Release
...
boost/1.78.0 from 'conancenter' - Cache
When calling
$ cmake -DCMAKE_BUILD_TYPE=Release ..
the above stated output is yielded.
I'm trying to compile sfml with cmake and conan package manager. Here is my conanfile.txt:
[requires]
sfml/2.5.0#bincrafters/stable
[options]
sfml:graphics=true
sfml:window=True
sfml:audio=True
sfml:network=True
sfml:system=True
[generators]
cmake
[imports]
And my cmake file:
cmake_minimum_required (VERSION 3.10)
project(projectx)
add_executable(
${PROJECT_NAME}
src/main.cpp
)
target_link_libraries(
${PROJECT_NAME}
${CONAN_LIBS}
)
rtype
And when i compile here is my error :
ERROR: Unable to find 'sfml/2.5.0#bincrafters/stable' in remotes
The bincrafters remote is deprecated IIRC. You should use the conancenter remote instead (this is already configured as one of your remotes in newer conan versions - check with conan remote list to be sure, it should list 'conancenter: https://center.conan.io [Verify SSL: True]').
In your conanfile.txt simply replace the bincrafters/stable part by _/_ (I'm not 100% sure but maybe you don't need that #_/_ part at all, i.e. sfml/2.5.0 could suffice, already). The conancenter remote should be used.
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