Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

Errors compiling C++ code for x86_64

I have a project (that uses pre-compiled headers) that uses different compiler options for SOME files.

For those files I have this is in my CMakelists.txt:

if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
set_source_files_properties(${AVX_Files}
    PROPERTIES
        COMPILE_OPTIONS "-mavx;-mavx2;-mfma;-mssse3;-msse4.2")
set_source_files_properties(avx_simd_check.cpp
    PROPERTIES
        COMPILE_OPTIONS "-mxsave")
endif()

When I build for ARM, it all works :)

When I try to build for X86_64, I get the following error for avx_simd_check.cpp:


error: current translation unit is compiled with the target feature '+xsave' but the AST file was not
1 error generated.

and for all the other files in question:

error: current translation unit is compiled with the target feature '+avx' but the AST file was not
error: current translation unit is compiled with the target feature '+avx2' but the AST file was not
error: current translation unit is compiled with the target feature '+fma' but the AST file was not
error: current translation unit is compiled with the target feature '+sse4.2' but the AST file was not
error: current translation unit is compiled with the target feature '+ssse3' but the AST file was not
5 errors generated.

How can I solve this please? David

Well that has changed! With the latest XCode update to 16.3 I can't specify those options for an ARM build :(

Which is OK, so long as I can work out how to avoid specifying them for an ARM target, but I NEED them for the x86_64 build.

But of course I still have the problem above ...

D.

You would probably find better responses in a CMake forum.

This question isn't about CMake it's about the compiler.

However I worked around the problem by building the files that needed the special compilation options for AVX into a different static library.

I think the issue is that the files in question don't use PCH, but the rest of the files do so. I think the parse tree for AST was built from the precompiled headers.

Errors compiling C++ code for x86_64
 
 
Q