Correctly modify through the set command
Use these two methods to effect the same effect under some cases (note that in some cases, not under all cases), their differences are as follows:
The compile option added by the
add_compile_optionscommand is for all compilers (including C and C ++ compilers).
set command settings
CMAKE_CXX_FLAGSvariables are only for C and C ++ compilers.
Therefore, in the compilation of the hybrid program of C/C ++ and OC, when setting “-X Objective-C ++”, it can only be usedadd_compile_optings to add compilation options, otherwise, C/C ++ will report inexplicable mistakes when compiling the OC code.
So, when C/C ++ and OC are mixed with compile, the cmakelists.txt should be written as follows:
set(CMAKE_EXE_LINKER_FLAGS “-framework Cocoa -framework AppKit -framework CoreData -framework Foundation”)
The corresponding G ++ command line parameters are as follows:
g++ -x objective-c++ -framework Cocoa -framework AppKit -framework CoreData -framework Foundation
, compile, can successfully produce executable files.