CMAKE:链接到项目目录之外的本地构建的静态库
我正在将几个项目转换为使用Cmake作为构建系统。这些项目之间有一些共享的库,我想与项目分开维护,这些项目统计地构建了应用程序和库。
所需的目录结构看起来像这样。
repos/
common/
LibA/
CMakeLists.txt
src/
CMakeLists.txt
<Lib sources>
build/
LibA.lib
<other libs>
AppA/
CMakeLists.txt
src/
CMakeLists.txt
<App sources>
build/
AppA.exe
<other apps>
到目前为止,我制作的CMAKE文件是;
liba/cmakelists.txt
cmake_minimum_required (VERSION 3.8)
project ("LibA")
# Include sub-projects.
add_subdirectory ("src")
liba/src/cmakelists.txt
cmake_minimum_required (VERSION 3.8)
add_library(
LibA STATIC
"Animal.cpp"
"Animal.h"
"Dog.h"
"Dog.cpp"
)
set_property(TARGET LibA PROPERTY CXX_STANDARD 11)
cmake_minimum_required (VERSION 3.8)
project ("AppA")
# Include sub-projects.
add_subdirectory("../common/LibA" "build")
add_subdirectory ("src")
appa/cmakelists.txt appa/src/cmakelists.txt
cmake_minimum_required (VERSION 3.8)
add_executable( AppA
main.cpp
)
target_link_libraries(AppA LibA)
set_property(TARGET AppA PROPERTY CXX_STANDARD 11)
使用此设置,APPA上的CMAKE成功,但是Main.cpp找不到Animal.H。
main.cpp
#include "Animal.h"
int main(int argc, char *argv[])
{
Animal* ann = new Animal();
ann->speak((char*)"Rawr");
return 0;
}
我假设我在Appa的Cmake文件中没有正确链接到liba。不幸的是,我还找不到有关如何在项目统计上链接在项目子目录之外的任何好示例。
I'm in the process of converting several projects to use CMake as the build system. These projects have some shared libraries between them that I would like to maintain separately from the projects, with the projects statically building the application and libraries together.
The desired directory structure would look something like this;
repos/
common/
LibA/
CMakeLists.txt
src/
CMakeLists.txt
<Lib sources>
build/
LibA.lib
<other libs>
AppA/
CMakeLists.txt
src/
CMakeLists.txt
<App sources>
build/
AppA.exe
<other apps>
The CMake files I've made thus far are;
LibA/CMakeLists.txt
cmake_minimum_required (VERSION 3.8)
project ("LibA")
# Include sub-projects.
add_subdirectory ("src")
LibA/src/CmakeLists.txt
cmake_minimum_required (VERSION 3.8)
add_library(
LibA STATIC
"Animal.cpp"
"Animal.h"
"Dog.h"
"Dog.cpp"
)
set_property(TARGET LibA PROPERTY CXX_STANDARD 11)
AppA/CMakeLists.txt
cmake_minimum_required (VERSION 3.8)
project ("AppA")
# Include sub-projects.
add_subdirectory("../common/LibA" "build")
add_subdirectory ("src")
AppA/src/CMakeLists.txt
cmake_minimum_required (VERSION 3.8)
add_executable( AppA
main.cpp
)
target_link_libraries(AppA LibA)
set_property(TARGET AppA PROPERTY CXX_STANDARD 11)
With this setup, running cmake on AppA is successful, however, main.cpp cannot find Animal.h.
main.cpp
#include "Animal.h"
int main(int argc, char *argv[])
{
Animal* ann = new Animal();
ann->speak((char*)"Rawr");
return 0;
}
I assume I'm not linking to LibA properly in AppA's CMake files. Unfortunately, I haven't been able to find any good examples of how to link outside of a project's subdirectories statically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论