Skip to content

Compilation issue when building "libxml2_example" on MacOS 26.1 #288

@d4rkc0nd0r

Description

@d4rkc0nd0r

Steps followed after cloning the project:

  • mkdir build && cd build in the repo root
  • cmake .. -DCMAKE_CXX_STANDARD=17 -DCMAKE_EXE_LINKER_FLAGS="$(pkg-config --libs protobuf)"
  • make libxml2_example

Generated Error

[ 72%] Built target protobuf-mutator-libfuzzer
[ 77%] Running cpp protocol buffer compiler on xml.proto
[ 81%] Building CXX object examples/xml/CMakeFiles/protobuf-mutator-xml.dir/xml_writer.cc.o
[ 86%] Building CXX object examples/xml/CMakeFiles/protobuf-mutator-xml.dir/xml.pb.cc.o
[ 90%] Linking CXX static library libprotobuf-mutator-xml.a
[ 90%] Built target protobuf-mutator-xml
[ 95%] Building CXX object examples/libxml2/CMakeFiles/libxml2_example.dir/libxml2_example.cc.o
[100%] Linking CXX executable libxml2_example
ld: warning: ignoring duplicate libraries: '-lc++'
ld: library '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/17/lib/darwin/libclang_rt.fuzzer_osx.a' not found
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [examples/libxml2/libxml2_example] Error 1
make[2]: *** [examples/libxml2/CMakeFiles/libxml2_example.dir/all] Error 2
make[1]: *** [examples/libxml2/CMakeFiles/libxml2_example.dir/rule] Error 2
make: *** [libxml2_example] Error 2
  • This is expected as the LLVM build from XCode SDK doesn't have LibFuzzer support.

Workaround

  • However the workaround for this would be to install LLVM using brew install llvm@17. I chose version 17 as the other versions of LLVM has undefined symbols error (tried LLVM 20 and 21) and ran the above commands with CC and CXX variables.
  • The error I get is:
ld: warning: building for macOS-16.0, but linking with dylib '/opt/homebrew/opt/protobuf/lib/libprotobuf.33.1.0.dylib' which was built for newer version 26.0

I have tried a lot of workarounds for this but there is some or the other error. How can I compile it on MacOS?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions