Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

makefile - define gets ignored by target_compile_definitions

I am looking to build a library and I need to pass two defines to that build, but cmake's target_compile_definitions() scrambles them in a manner that renders them unusable.

The two defines are:

  • -D'_LIB_EXCEPTION_ABI=__attribute__((visibility("default")))'
  • -D'_LIB_FALLTHROUGH()=((void)0)'

Unfortunately, the first one gets translated to (in the command build line):

  • -D'_LIB_EXCEPTION_ABI="\__attribute__((visibility("default")))'"

While the second one is missing altogether from the command line.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

CMake has known limitations on what compile definitions could be.

Among these limitations are function-style definitions (_LIB_FALLTHROUGH()) and ones containing double quotes (").

Instead of attempting to overcome these limitations, it is recommended to create a separate header file with these compile definitions:

#define _LIB_EXCEPTION_ABI __attribute__((visibility("default")))
#define _LIB_FALLTHROUGH() ((void)0)

This header file could be included with -include compiler option (gcc) or /FI option (Visual Studio).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...