【发布时间】:2020-11-02 21:06:09
【问题描述】:
我似乎已经成功构建了我的第一个本地柯南包并将其上传到我的本地工件..我也可以在其他项目的依赖项中添加全名..
[requires]
thrift/0.13.0
mypkg/0.0.1@user/channel
[generators]
cmake
我可以在我的OtherProjectCMakeLists.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 文件或我希望它可用的任何标题?我是否错误地构建了我的食谱?还是我只需要更改在代码中引用新柯南包的方式?
OtherProject/sumptionHeader.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
听起来我需要稍微改变一下我的食谱......
【问题讨论】:
-
我建议检查生成的
conanbuildinfo.cmake文件,然后检查文件夹的 INCLUDE_DIRS 变量,并检查标题是否实际上在该文件夹中。如果不是,我会检查包创建过程(强烈建议使用test_package功能来自动执行此操作)。你可以从一个可以工作的conan new hello/0.1 -s -t开始测试包,然后为你自己的代码定制它。 -
我确实找到了我的
INCLUDE_DIRS_MY-PKG.. 进入文件夹... 发现文件夹结构可能不是它应该的... 我想我需要以某种方式制作根文件夹它当前设置的子文件夹.. 现在将添加此详细信息以发布 -
谢谢你,drodri,我明白了.. 你能发布这个基本上我必须在我的食谱中更改这一行才能以正确的方式复制文件吗? ``` self.copy("*.h", dst="include", src="my-pkg/source/cppclient/client") ```