【问题标题】:add flags using cmake使用 cmake 添加标志
【发布时间】:2021-05-31 14:11:19
【问题描述】:

我用 cmake 创建了一个静态库。我有一个 library.h、library.cpp 和 main.cpp。 我在 library.h 中声明并在 library.cpp 中实现的所有函数。我使用默认制作文件(全部制作)制作项目。 现在我声明了一些宏(例如#ifndef MEM ... #else ...)。如果使用宏,则应添加标志:-DMEM -DPREP=20 -DM=1200。我在 make 文件中添加了以下内容:

swtest: CPPFLAGS += -DM=1200 -DMEM -DPREP=20 -g

然后我使用:

make swtest

然后编译 main.cpp:

g++ main.cpp -o main lib.a -DMEM -DPREP=20 -DM=1200 -g

但它不起作用。 我想我应该在我的 cmakelists 文件中添加一些代码,但我不知道怎么做! 我强调我的宏添加到 library.cpp 而不是 main.cpp。 请注意,我正在使用 clion。

【问题讨论】:

  • 为什么你从makefile显示sn-ps,却声称使用的是CMake?
  • 如果你想对不同的源文件使用不同的编译器标志,那么使用set_source_files_properties命令,如that answer中所述。

标签: c++ makefile cmake preprocessor


【解决方案1】:

您需要确保在编译 library.cpp 时指定定义。

【讨论】:

  • 如果我知道怎么做,我就不会再问了!!
猜你喜欢
  • 1970-01-01
  • 2014-08-23
  • 2016-07-15
  • 2019-05-24
  • 1970-01-01
  • 2020-10-06
  • 2019-03-11
  • 1970-01-01
相关资源
最近更新 更多