C/C++输出预处理文件总是失败

idfiyjo8  于 2023-05-08  发布在  C/C++
关注(0)|答案(1)|浏览(213)

一个非常简单的源代码如下:

#include <stdio.h>

#define ADD(x,y) x+y

int main(int argc, char *argv[])
{
printf("%d\n",ADD(1,2));
return 0;
}

CMakeLists.txt是:

cmake_minimum_required(VERSION 3.14)

project(url_email LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_compile_options(-E -v)

add_executable(url_email main.cpp)

target_link_libraries(url_email)

我试着输出像url_email.i这样的预处理文件,但链接器总是说:

/usr/bin/ld:CMakeFiles/url_email.dir/main.cpp.o: file format not recognized; treating as linker script

有什么问题吗?
我尝试输出预处理文件,如url_email.i,其中包含处理后的宏定义

4sup72z8

4sup72z81#

使用-E选项时,对象文件(main.cpp.o)似乎已经更改为ASCII格式,扩展了宏定义,不再有url_email.i文件了。谢谢大家的回答。

extern void funlockfile (FILE *__stream) noexcept (true);
# 885 "/usr/include/stdio.h" 3 4
extern int __uflow (FILE *);
extern int __overflow (FILE *, int);
# 902 "/usr/include/stdio.h" 3 4
}
# 2 "/home/hwb/Project/url_email/main.cpp" 2

# 5 "/home/hwb/Project/url_email/main.cpp"
int main(int argc, char *argv[])
{
    printf("%d\n",1 +2);

    return 0;
}

相关问题