- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 CMake 项目,同时构建一个静态库并将其与其他代码链接到可执行文件中。由于我不会详细说明的原因,我希望使用 --whole-archive
链接器标志进行此链接。
现在,这个标志很棘手,因为您不能将其添加到任何地方 - 您必须切换它,然后列出您希望它应用的库,然后取消切换它。
我在某处读到(我忘记了 URL),如果您有一个预先存在的库,则可以通过执行以下操作来有效地添加此链接器标志:
# Just an example, find_library calls should really be isolated to separate find modules
find_library(FOO_LIBRARY foo)
set(FOO_LIBRARY "-Wl,--whole-archive ${FOO_LIBRARY} -Wl,--no-whole-archive")
add_executable(hello main.c)
target_link_libraries(hello ${FOO_LIBRARY})
没关系。但是,如果您正在构建的静态库没有预先存在的变量(即您有 add_library()
CMake 命令的静态库,该怎么办? )?您是否必须手动指示其路径而不是 ${FOO_LIBRARY} ?或者是否可以使用其他一些技巧来获取 CMake 将在命令行上放置的路径?
此外,如果我使用某种类似 ${FOO_LIBRARY}
的字符串而不是我的静态库目标标识符 - 我相信 CMake 可能会错过依赖项,即它可能不会重新链接使用修改后的库(或者甚至不构建它),因为 target_link_libraries 命令将看到一个奇怪的字符串,而不是另一个目标的标识符。
最佳答案
这可以通过以下方式完成:
add_dependencies(the_exe the_static_lib)
set_target_properties(the_exe LINK_FLAGS
"-L/path/to/the_static_lib -Wl,--whole-archive,-lthe_static_lib,--no-whole-archive")
-L/path/to/the_static_lib
的值透明地遵循您指定的输出目录目标,或者目标的默认输出目录(如果不这样做)。例如。如果the_static_lib
是只需在构建目录中输出,然后 -L/path/to/the_static_lib
将是-L.
这是一个以相当一般的方式说明的项目,我们在其中具有源代码和标题的结构化子目录以及独特的常规输出目录,bin
, lib
$ ls -R
.:
app build CMakeLists.txt foobar inc
./app:
main.c
./build:
./foobar:
bar.c foo.c
./inc:
foobar.h
带有文件:
app/main.c
#include <foobar.h>
int main(void)
{
foo();
bar();
return 0;
}
foobar/foo.c
#include <foobar.h>
#include <stdio.h>
void foo(void)
{
puts(__func__);
}
foobar/bar.c
#include <foobar.h>
#include <stdio.h>
void bar(void)
{
puts(__func__);
}
inc/foobar.h
#ifndef FOOBAR_H
#define FOOBAR_H
void foo(void);
void bar(void);
#endif
CMakeLists.txt (1)
cmake_minimum_required(VERSION 3.0)
project(app)
include_directories(inc)
add_library(foobar STATIC foobar/foo.c foobar/bar.c)
set_target_properties(foobar
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
add_executable(app app/main.c)
add_dependencies(app foobar)
set_target_properties(app PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
LINK_FLAGS "-Llib -Wl,--whole-archive,-lfoobar,--no-whole-archive")
我们想要 ./build/lib/libfoobar.a
来自./foobar/foo.c
和./foobar/bar.c
。我们想要 ./build/bin/app
来自./app/main.c
,链接整个文件./build/lib/libfoobar.a
生成、构建并运行:
$ cd build; cmake ..; make; ./bin/app
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/imk/develop/so/cmake_prob/build
Scanning dependencies of target foobar
[ 20%] Building C object CMakeFiles/foobar.dir/foobar/foo.c.o
[ 40%] Building C object CMakeFiles/foobar.dir/foobar/bar.c.o
[ 60%] Linking C static library lib/libfoobar.a
[ 60%] Built target foobar
Scanning dependencies of target app
[ 80%] Building C object CMakeFiles/app.dir/app/main.c.o
[100%] Linking C executable bin/app
[100%] Built target app
foo
bar
类似地,如果而不是 CMakeLists.txt
我们有:
CMakeLists.txt (2)
cmake_minimum_required(VERSION 3.0)
project(app)
include_directories(inc)
add_subdirectory(foobar)
add_executable(app app/main.c)
add_dependencies(app foobar)
set_target_properties(app PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
LINK_FLAGS "-Llib -Wl,--whole-archive,-lfoobar,--no-whole-archive")
分别:
foobar/CMakeLists.txt (1)
add_library(foobar STATIC foo.c bar.c)
set_target_properties(foobar
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
并且使用相同的分隔,但默认输出目录,我们将有:
CMakeLists.txt (3)
cmake_minimum_required(VERSION 3.0)
project(app)
include_directories(inc)
add_subdirectory(foobar)
add_executable(app app/main.c)
add_dependencies(app foobar)
set_target_properties(app PROPERTIES
LINK_FLAGS "-Lfoobar -Wl,--whole-archive,-lfoobar,--no-whole-archive")
foobar/CMakeLists.txt (2)
add_library(foobar STATIC foo.c bar.c)
会是这样:
$ cd build; cmake ..; make; ./app
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/imk/develop/so/cmake_prob/build
Scanning dependencies of target foobar
[ 20%] Building C object foobar/CMakeFiles/foobar.dir/foo.c.o
[ 40%] Building C object foobar/CMakeFiles/foobar.dir/bar.c.o
[ 60%] Linking C static library libfoobar.a
[ 60%] Built target foobar
Scanning dependencies of target app
[ 80%] Building C object CMakeFiles/app.dir/app/main.c.o
[100%] Linking C executable app
[100%] Built target app
foo
bar
关于build - 在您构建的库上使用 CMake 中的 --whole-archive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43437424/
Xcode 4 中的以下操作有什么作用? 为测试而构建 为运行而构建 为分析而构建 为存档而构建 我不确定何时使用这些(或是否使用其中任何一个)。 最佳答案 Running 用于运行您的应用(在 Ma
工具: Jenkins 版1.470 Maven 2 颠覆 环境 假设我的构建有许多项目 A-D。如图所示,依赖关系图存在。也就是说:B 依赖于 A 中的类,C 依赖于 B 中的类,D 依赖于 A 中
我正在创建一个软件项目,我想使用 autotools 为我生成 makefile 等脚本,我手动创建了 Makefile.am 和 configure.in 文件,我正在使用 autogen.sh 脚
什么yarn build命令做什么? 是 yarn build和 npm build相同?如果不是有什么区别? 最佳答案 yarn build和 npm build默认情况下不是现有的命令。我想你是说
如果我有一个包含许多相互依赖的项目的大型代码库,例如,projects/A、projects/B 和 projects/C ,其中 A 需要 B,B 需要 C,每个项目都有一个Cake 构建脚本,例如
我正在尝试使用 Wix/Detox 来测试我的 react-native 应用程序(iOS 版本)。我已成功遵循 https://github.com/wix/detox/blob/master/do
我们有许多编译 .NET 代码的 Nant 脚本。这些构建需要 5 到 10 分钟才能运行,我想找到一种方法来加速它们。 我们的 Nant 脚本看起来像
你好 当我在 windows 下使用 gnu 构建 ffmpeg-3.4.1 时,谁能帮我解决这个错误: /tmp/9747a756ee05ef34cc3fcf51eabde826/sysroot/u
构建解决方案/项目/程序意味着什么?我想确保我的定义是正确的(所以我在交谈时听起来不像个白痴)。在 IDE 中,您可以(如果我错了,请纠正我)编译源代码/编程代码为计算机可读的机器代码。您可以调试程序
为什么 Eclipse 在构建 Android 项目时会陷入无限循环,用于构建工作区...和(重新)构建工作区...和(重新)构建工作区... 这是一个已知的错误吗? 摆脱这个循环的正确方法是什么?
我的 Angular 项目是 @Angular4.3.3 ng build -prod 构建需要 77 秒 ng build --prod --build-optimizer=true 构建需要 19
所以我刚刚使用命令创建了一个 React Native 项目 react-native init "项目名称" 我进入应用程序级别的 build.gradle 以连接 firebase,但出现错误提示
我想弄清楚 TFS Online 2017 中的两个预定义变量之间是否存在差异:$(Build.Repository.LocalPath)和 $(Build.SourcesDirectory) .我有
编译项目时,当系统用户名匹配时,此脚本应将 Xcode 项目的构建版本递增 1。请记住,这些只是 Target->Build Phases->Run Script in Xcode 中脚本(不是 Ap
是否有一种工具可以在给定 MS Build 项目文件的情况下构建一个视觉对象,显示将在何时以及从哪个导入文件执行哪个目标? 如果给定一个解决方案文件,它会构建项目构建顺序的视觉效果? 最佳答案 是的,
我正在尝试使用 Bazel 进行以下设置。通过调用“bazel build”,Python 脚本应该生成未知数量的具有随机名称的 *.cc 文件,然后将这些文件编译成单个静态库(.a 文件),所有这些
我正在将我的 Cmake 项目迁移到 Bazel。我项目的根目录是 build我用来运行 Cmake 的文件夹。 迁移到 Bazel ,我需要创建一个 BUILD我的项目根目录下的文件。但是,在 ma
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 5 年前。 此帖子已于
当我的Dockerfile如下所示时,它运行良好。 ... RUN pip install git+https://user_name:my_password@github.com/repo_name
当前的自动构建功能集是否可以从存储库中添加新标签并标记生成的图像?还是我需要3party服务将新标签自动推送到Docker Registry? 最佳答案 目前不行。 当前(2014年10月)尚无Doc
我是一名优秀的程序员,十分优秀!