Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...