- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我编译C++程序/tmp/src/main.cc
#include <iostream>
int main() {
#ifdef demo1
std::cout << "Output from demo1\n";
#endif
#ifdef demo2
std::cout << "Output from demo2\n";
#endif
}
使用文件 /tmp/src/CMakeLists.txt 中的构建说明
cmake_minimum_required(VERSION 3.11)
project(test_save_temps LANGUAGES CXX)
function(my_add_executable name)
add_executable(${name})
target_sources(${name} PRIVATE main.cc)
# target_compile_options(${name} PRIVATE --save-temps)
target_compile_definitions(${name} PRIVATE
${name}
)
endfunction()
my_add_executable(demo1)
my_add_executable(demo2)
一切正常
ubuntu@laptop:/tmp$ mkdir /tmp/build
ubuntu@laptop:/tmp$ cd /tmp/build
ubuntu@laptop:/tmp/build$ cmake -G Ninja /tmp/src
-- The CXX compiler identification is GNU 8.2.0
-- 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: /tmp/build
ubuntu@laptop:/tmp/build$ ninja
[4/4] Linking CXX executable demo1
ubuntu@laptop:/tmp/build$ ls
build.ninja CMakeCache.txt CMakeFiles cmake_install.cmake demo1 demo2 rules.ninja
ubuntu@laptop:/tmp/build$ ./demo1
Output from demo1
ubuntu@laptop:/tmp/build$ ./demo2
Output from demo2
ubuntu@laptop:/tmp/build$
但是如果我从文件 /tmp/src/CMakeLists.txt 中删除注释激活线路
target_compile_options(${name} PRIVATE --save-temps)
同样做
ubuntu@laptop:/tmp$ mkdir /tmp/build_with_save_temps
ubuntu@laptop:/tmp$ cd /tmp/build_with_save_temps
ubuntu@laptop:/tmp/build_with_save_temps$ cmake -G Ninja /tmp/src
-- The CXX compiler identification is GNU 8.2.0
-- 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: /tmp/build_with_save_temps
ubuntu@laptop:/tmp/build_with_save_temps$ ninja
[4/4] Linking CXX executable demo1
ubuntu@laptop:/tmp/build_with_save_temps$ ls
build.ninja CMakeCache.txt CMakeFiles cmake_install.cmake demo1 demo2 main.ii main.s rules.ninja
ubuntu@laptop:/tmp/build_with_save_temps$ ./demo1
Output from demo1
ubuntu@laptop:/tmp/build_with_save_temps$ ./demo2
Output from demo1
ubuntu@laptop:/tmp/build_with_save_temps$ find . -name '*.s'
./main.s
ubuntu@laptop:/tmp/build_with_save_temps$
程序 demo2 的输出不正确。
我希望在构建目录中找到两个版本的程序集文件 main.s。
这里我提供一些关于我的电脑系统的额外信息
如何修改 /tmp/src/CMakeLists.txt 以保留两个版本的程序集文件 main.s?
当我按照答案 https://stackoverflow.com/a/53811064/757777 中的建议使用 -save-temps=obj
时,一切都开始工作了由用户fritzone。
我换了
target_compile_options(${name} PRIVATE --save-temps)
与
target_compile_options(${name} PRIVATE -save-temps=obj)
现在我得到了两个程序集文件
ubuntu@laptop:/tmp/build2$ find . -name '*.s'
./CMakeFiles/demo2.dir/main.cc.s
./CMakeFiles/demo1.dir/main.cc.s
ubuntu@laptop:/tmp/build2$
并且可执行文件 demo1 和 demo2 按预期工作
ubuntu@laptop:/tmp/build2$ ./demo1
Output from demo1
ubuntu@laptop:/tmp/build2$ ./demo2
Output from demo2
ubuntu@laptop:/tmp/build2$
最佳答案
您需要为编译器指定-save-temps=obj
选项,以便根据目标文件保存临时文件,根据: https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html#Developer-Options
因此,您需要将 cmake 文件修改为:
target_compile_options(${name} PRIVATE -save-temps=obj)
(或类似的)以便根据您尝试编译的应用程序的名称保存临时文件。
关于c++ - 当多个目标使用相同的源文件时,如何使用 --save-temps 保留程序集文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53810792/
for x in [temp for temp in xlist if temp xmax: continue 会起作用。 (你的 for 循环的其余部分是做什么的?)如果它可以只使用一个 list-
我正在学习 C 的 udemy 类(class),发现这个问题不是都声明是相同的吗?如果是,为什么答案不同 源代码: #include void swap(int *a, int *b){
#include #include void test( int * ); struct node { int data; struct node * next; }; int m
所以我在练习一些链表问题,但我一直把假设弄混了//这是一个只有头部的单向链表 // what is the difference between ListNode temp = head; while
我有一个 Windows Server 2008 32 位,当我输入 %temp% 时,它会将我带到 ..AppData\Local\Temp\1\或 ..AppData\Local\Temp\2 而
在学习链表编码的过程中,我遇到了这两个东西,无法理解它们之间的区别,让我感到困惑。我一直在学习的这本书在我们在链表末尾添加新节点的部分解释了“temp=*q”。 So, if the list is
谁能说出下面代码的内部过程 //instead of 1 it displays -1 最佳答案 echo ~$temp; ^bitwise not operator 假设 32 位
我想知道hadoop.tmp.dir和mapred.temp.dir有什么区别,而且mapred.temp.dir [不建议使用]与mapreduce.cluster.temp.dir有何不同 最佳答
我的输入来自使用 DataInputSteam 的 socket,并且因为我可以将多个不同的字符串值全部分配给同一个 clientDayOfWeek 字符串,我无法弄清楚如何将进入同一个 ArrayL
在做一些基于二叉搜索树的问题时......我在函数调用中有点困惑: void find(node* root,node*& temp) { blah blah... } int main()
为什么下面的代码不起作用?据我所知,当 temp 达到 NULL 时,(new)ing 它应该创建一个 temp 指向它的新节点。奇怪的是,将 while 条件更改为 temp->next!=NULL
我有一个 JMenuItem 实例(比如说 TEMP)。我想知道添加了 TEMP 的 JMenu 的名称是什么。我该怎么做? 最佳答案 您可以尝试以下代码来获取给定 JMenuItem 的 JMenu
我得到了相同的结果,有什么区别?哪个更好?temp 是一个 int,从 reader.read() 读取 System.out.print((char)temp); System.out.print(
我试图通过以下示例中的 temp 变量检查“temp = ( volatile 无符号短*) add ”中的添加值: main() { unsigned short add = 0x01;
我有一个网络作业,在 %temp% 文件夹中写入一些数据,该文件夹映射到 d:\local\temp。 当我在 Azure 门户上使用控制台工具时,数据就在那里,位于 d:\local\temp 上。
我有下面的内容,用作启动 powershell 的批处理文件(太长,无法详细介绍,但它在另一个脚本中使用)。 无论如何,我注意到 %systemroot%\temp 和 %systemroot% 不起
我尝试在这里和整个 Internet 上进行研究,但由于伪代码编写相当多样化,许多人使用不同的符号来表示不同的事物,我找不到任何可能符合我的问题的内容。 给定以下内容:n 阶数组 A(不一定已经排序)
Replace Temp with Query 重构方法现在被广泛推荐,但是似乎效率很低, yield 很小。 Martin Fowler 网站的方法给出了以下示例: 将表达式提取到方法中。用表达式替
当我们有什么操作需要使用到命令的就可以打开运行,然后直接向里面输入命令就可以完成一些操作。因为有用户想知道%temp%输入命令行是什么意思,所以小编就来为大家解答了这个命令的意思,它一般是用于清除垃
我知道之前有人问过这方面的变体(例如 https://groups.google.com/forum/#!topic/snakemake/4kslVBX2kew ),但我没有看到明确的解决方案。 如果
我是一名优秀的程序员,十分优秀!