![](/img/trans.png)
[英]Using conan packages in CMake: Library 'mylibrary.a' not found in package
[英]my first conan package not getting found by CMAKE?
我似乎已經成功構建了我的第一個本地 conan 包並將其上傳到我的本地 artifactory .. 我也可以在其他項目的依賴項中按全名添加它,例如..
[requires]
thrift/0.13.0
mypkg/0.0.1@user/channel
[generators]
cmake
我可以在我的OtherProject
CMakeLists.txt 中鏈接它而不會出錯
cmake_minimum_required(VERSION 2.8.12)
project(OtherProject)
add_compile_options(-std=c++11)
# Using the "cmake" generator
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_executable(OtherProject src/Main.cpp)
target_link_libraries(OtherProject CONAN_PKG::my-pkg)
但是當我嘗試在我的消費項目的 C++ 中引用它時,它找不到mypkg.a
文件或我希望它可用的任何頭文件? 我是否錯誤地構建了我的食譜? 還是我只需要更改在代碼中引用新柯南包的方式?
其他項目/消費Header.H
#pragma once
#include "MyPkgsHeader.h"
構建時出錯
> cmake --build .
Scanning dependencies of target OtherProject
[ 50%] Building CXX object CMakeFiles/OtherProject.dir/src/Main.cpp.o
In file included from /OtherProject/src/Main.cpp:12:
/OtherProject/src/TestCppClient.h:8:10: fatal error: 'MyPkgsHeader.h' file not found
#include "MyPkgsHeader.h"
^~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/OtherProject.dir/src/Main.cpp.o] Error 1
make[1]: *** [CMakeFiles/OtherProject.dir/all] Error 2
make: *** [all] Error 2
MyPkg 食譜 conanfile.py
from conans import ConanFile, CMake, tools
class MyPkgConan(ConanFile):
name = "mypkg"
version = "0.0.1"
license = "<Put the package license here>"
author = "<Put your name here> <And your email here>"
url = "<Package recipe repository url here, for issues about the package>"
description = "<Description of mypkg here>"
topics = ("<Put some tag here>", "<here>", "<and here>")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = {"shared": False}
generators = "cmake"
def source(self):
self.run("git clone --depth 1 --branch 0.0.1 git@github.com:PROJECT/my-pkg.git")
tools.replace_in_file("my-pkg/CMakeLists.txt", " LANGUAGES CXX )",
''' LANGUAGES CXX )
add_compile_options(-std=c++11)''')
def build(self):
cmake = CMake(self)
cmake.configure(source_folder="my-pkg")
cmake.build()
# Explicit way:
# self.run('cmake %s/hello %s'
# % (self.source_folder, cmake.command_line))
# self.run("cmake --build . %s" % cmake.build_config)
def package(self):
self.copy("*.h", dst="include", src="my-pkg")
self.copy("*hello.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.dylib", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)
def package_info(self):
self.cpp_info.libs = ["mypkg"]
#EDIT:看到包含文件夾的問題
按照指示,我查看了我的conanbuildinfo.cmake
並專門查找了CONAN_INCLUDE_DIRS_MY-PKG
下的路徑
源文件位於我沒想到的文件夾結構中
/../<conanhash>/include/source/cppclient/client/MyPkgsHeader.h
當我被期待的時候
/../<conanhash>/client/MyPkgsHeader.h
or
/../<conanhash>/MyPkgsHeader.h
聽起來我需要稍微改變一下我的食譜……
調試此類問題的正確過程如下:
requires = "pkg/version..."
,或者再次執行conan install
以獲取該依賴項並生成一個新的conanbuildinfo.cmakeconan create
package()
方法內self.copy()
調用中的某些錯誤模式或路徑。 對於標頭,調用類似於self.copy("*.h", dst="include", src="<path/to/headers>")
,其中src
參數可能是錯誤的。conan create
后轉到 Conan 緩存文件夾並在內部導航,並手動檢查預期的文件是否在那里。 為了避免錯誤創建包的問題,非常推薦使用test_package
功能。 簡而言之,它是一個“消費者”項目,連同conan create
時將自動觸發的包配方,它將安裝+構建+執行您告訴它的任何應用程序,對包進行一些基本檢查並盡早失敗如果不正確,盡可能。 檢查“test_package”文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.