如果我只有.o文件,则可以反映可执行文件中标头文件中的更改
Can I reflect changes in header file in executables if i have only .o files for the dependent programs
我有两个文件
main.cpp
#include<iostream>
#include "tmp1.h"
using namespace std;
int main() {
cout<<factorial<7>::value<<endl;
}
和tmp1.h
#include<iostream>
using namespace std;
template <unsigned n>
struct factorial
{
enum { value = n * factorial<n-1>::value };
};
template <>
struct factorial<0>
{
enum { value = 1 };
};
i使用-c flag
编译main.cpp g -c main.cpp生成main.o文件
然后,我将阶乘模板的基本案例更改为" value = 2",然后使用
链接它g -o tmpex main.o tmp1.h
但是,当我运行可执行文件时,它会输出5040而不是10080,这是我需要的新值。
我可以做些什么,即使我只有main.o文件,而不是其源代码,我也可以更改标头文件并反映新的可执行文件中的更改
摘要
我有一个依赖的main.o文件和标头。我想对标头文件进行更改,并反映新可执行文件中的更改,而无需main.cpp文件
不,你不能。该模板是在 compilation epta中实例化的,即生成.o文件时。将标题添加到链接阶段不会有任何效果
相关文章:
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- 如何使 windows 命令提示符在C++可执行文件上显示返回值?
- CMake:如何将库 A 链接到库 B,然后将可执行文件链接到库 A
- 如何使字符串出现在编译的二进制可执行文件的开头?
- 程序在使用 system() 启动另一个可执行文件时停止
- 如何更改使用 CPack 安装的可执行文件的名称?
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- CMake:我们可以为一组不形成可执行文件或库的特定文件指定包含目录吗?
- 如何将图像传入C++可执行文件并将输出图像存储在新目录中?
- 共享库 (.so) 没有扩展名的 Linux 可执行文件之间的区别?
- 如何在 linux 可执行文件中使用静态库
- 错误:当我从"WinDbg"打开可执行文件时,找不到符号文件。默认导出 ntdll 的符号.dll
- 编译的C可执行文件被Windows defender检测为病毒
- Linux 可执行文件通过 dlopen 在emplace_back崩溃打开共享库
- 是否可以在命令行中将输入参数传递给可执行文件
- 如何在可执行文件中存储常量数组?
- 如果包含映射的静态库与可执行文件和动态库链接,静态映射(变量)是否会被多次释放?
- c ++:如何为每个特征制作特定的二进制文件(可执行文件)?
- 在英特尔C++编译器 (Linux) 的配置搜索路径中找不到文件可执行文件
- 在运行时动态更新二进制文件(可执行文件)而不停止的任何类型的方法