I have a cross platform CMake project which uses a few third party dependencies. On Windows this builds fine, however when building on Mac using ninja I get the following error when linking Optick:
[949/972] Linking CXX shared library Engine/External/optick/libOptickCore.dylib
FAILED: Engine/External/optick/libOptickCore.dylib
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c -x objective-c -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -dynamiclib -Wl,-headerpad_max_install_names -o Engine/External/optick/libOptickCore.dylib -install_name @rpath/libOptickCore.dylib Engine/External/optick/CMakeFiles/OptickCore.dir/src/optick_capi.cpp.o Engine/External/optick/CMakeFiles/OptickCore.dir/src/optick_core.cpp.o Engine/External/optick/CMakeFiles/OptickCore.dir/src/optick_gpu.cpp.o Engine/External/optick/CMakeFiles/OptickCore.dir/src/optick_gpu.d3d12.cpp.o Engine/External/optick/CMakeFiles/OptickCore.dir/src/optick_gpu.vulkan.cpp.o Engine/External/optick/CMakeFiles/OptickCore.dir/src/optick_message.cpp.o Engine/External/optick/CMakeFiles/OptickCore.dir/src/optick_miniz.cpp.o Engine/External/optick/CMakeFiles/OptickCore.dir/src/optick_serialization.cpp.o Engine/External/optick/CMakeFiles/OptickCore.dir/src/optick_server.cpp.o && :
Engine/External/optick/CMakeFiles/OptickCore.dir/src/optick_capi.cpp.o:1:1: error: source file is not valid UTF-8
<CF><FA><ED><FE><U 000C><U 0000><U 0000><U 0001><U 0000><U 0000><U 0000><U 0000><U 0001><U 0000><U 0000><U 0000><U 0004><U 0000><U 0000><U 0000><U 0008><U 0002><U 0000><U 0000><U 0000> <U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0019><U 0000><U 0000><U 0000><88><U 0001><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000><U 0000>H
^
These errors seem to happen on all object files generated from the OptickCore target.
The project is generated via CMake and it configures fine.
The C compiler identification is AppleClang 14.0.0.14000029
The CXX compiler identification is AppleClang 14.0.0.14000029
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c - skipped
Detecting CXX compile features
Detecting CXX compile features - done
Optick in the CMake script is linked via target_link_libraries
where I link OptickCore
as PUBLIC
and then add the Optick CMakeLists.txt
as a subdirectory.
The charset of the source files are all us-ascii
matthewloveday@192 src % file -I optick_capi.cpp
optick_capi.cpp: text/x-c; charset=us-ascii
And the charset of the object file is binary
matthewloveday@192 src % file -I optick_capi.cpp.o
optick_capi.cpp.o: application/x-mach-binary; charset=binary
I've never dealt with this error before so I'm not sure where to start, any help is appreciated!
CodePudding user response:
The error is in the not shown CMakeLists.txt.
You're telling AppleClang that all of its inputs are Objective-C file sources: -x objective-c
, whereas you are given the object files optick_capi.cpp.o optick_core.cpp.o ...
. AppleClang correctly is telling you that optick_capi.cpp.o
is not a UTF-8 encoded Objective-C source file.
CodePudding user response:
My guess would be that you're somehow building Optik so that it builds its object files into its own source directory. As it has a really bad glob for source files it'll pick up any object files as sources too.
You should change the glob to only pick up cpp and header files or even better don't use a glob at all as recommended by cmake