I have a lib that provides both libxxx_x86_64.a and libxxx_arm64.a. When linking using ld x86_64.a is skipped,
ld: warning: ignoring file _pod_work_dir/Pods/____/libs/______x86_64.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
however lld won't do so
1d64.11d: error: _pod_work_dir/Pods/_____/libs/______x86_64.a(___+___.o)has architecture x86_64 which is incompatible with target architecture arm64
Is there an option with lld I can make this behavior a warning instead of error.
the lib is downloaded directly into build dir by cmake or pods script like this. So the project just try to link x86_64.a as well.
Related
I'm hitting an issue with some fairly basic Protobuf files in a library of mine. This is built as a static library successfully but then when compiling tests (Catch2) and linking to the same protobuf library I'm getting the below undefined symbol:-
[build] Starting build
[proc] Executing command: /usr/local/bin/cmake --build /Volumes/TB3-1/git/skunkworks/herald-for-cpp/build --config Debug --target herald-tests --
[build] [1/1 100% :: 0.182] Linking CXX executable herald-tests/herald-tests
[build] FAILED: herald-tests/herald-tests
[build] : && /usr/bin/clang++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names herald-tests/CMakeFiles/herald-tests.dir/test-templates.cpp.o herald-tests/CMakeFiles/herald-tests.dir/test-util.cpp.o herald-tests/CMakeFiles/herald-tests.dir/mesh-tests.cpp.o herald-tests/CMakeFiles/herald-tests.dir/main.cpp.o -o herald-tests/herald-tests herald/libherald.a /usr/local/lib/libprotobuf.a /usr/local/opt/openssl#3/lib/libcrypto.a && :
[build] Undefined symbols for architecture x86_64:
[build] "google::protobuf::internal::InternalMetadata::~InternalMetadata()", referenced from:
[build] google::protobuf::MessageLite::~MessageLite() in libherald.a(modem.pb.cc.o)
[build] google::protobuf::MessageLite::~MessageLite() in libherald.a(mesh.pb.cc.o)
[build] google::protobuf::MessageLite::~MessageLite() in libherald.a(models.pb.cc.o)
[build] ld: symbol(s) not found for architecture x86_64
[build] clang: error: linker command failed with exit code 1 (use -v to see invocation)
[build] ninja: build stopped: subcommand failed.
[build] Build finished with exit code 1
The super interesting thing is it even complains about the missing symbol from the ~MessageLite call when I force SPEED instead of LITE_RUNTIME. Doesn't seem to matter whether I link the library and programme to the dylib or the static lib on my mac, whether the full library or the lite library. Tried both SPEED and LITE_RUNTIME in my proto files with exactly the same result.
I've been struggling with this a while. Any ideas greatly appreciated.
Note: My library's target platform ranges from a container on a server to an embedded hardware device. These particular tests are compiled local (Mac OS X x86_64 Intel Mac in my case currently).
This issue was tracked here and ought to be fixed in the recently released Protobuf 3.21.3.
The library builds that ship with package managers are usually built with NDEBUG defined (-DNDEBUG to the compiler, #define NDEBUG in the code). Usually this just turns off checking assert() macros, but Protobuf keys on this symbol to turn on and off its own internal debugging. It turns out that in release mode the InternalMetadata destructor was always inlined and (with -fvisibility-inlines-hidden in the compiler options) never produced a symbol to link against, while in debug mode it was not always inlined and needed to be linked against.
So trying to build user code that didn't define NDEBUG for the Protobuf headers would result in code that needed to link against that destructor, which wouldn't be in the release Protobuf packaged libraries.
The workaround is to use -DNDEBUG in your application, or to build a debug build of Protobuf to link against, or to use a Protobuf new enough (3.21.3+) or old enough (I think <=3.19) to not have this particular problem.
The only remaining mystery is why the whole Internet noticed this bug in the past few days, when it's been there for much longer.
I am trying to compile glfw from source on Mac with M1 arm64 processor, and while running the linker, cmake strangely is trying to link the project for x86_64 architecture, while the binaries were built for arm64.
I clone the project, create build folder named cmake-build-debug, generate build system in it with the Makefile etc. as follows:
git clone https://github.com/glfw/glfw.git
cd glfw
mkdir cmake-build-debug
cd cmake-build-debug
cmake -S .. -B . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_HOST_SYSTEM_PROCESSOR=arm64 -DCMAKE_SYSTEM_PROCESSOR=arm64
This works fine. But now that I build it with make or cmake --config Debug --build ., the .o binaries are generated perfectly fine, but linker script is incorrectly invoked by cmake with x86_64 target architecture for some reason:
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Including Cocoa support
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/burkov/Documents/Projects/open-source/glfw/cmake-build-debug
[ 47%] Built target glfw
Scanning dependencies of target wave
[ 50%] Linking C executable wave.app/Contents/MacOS/wave
ld: warning: ignoring file CMakeFiles/wave.dir/wave.c.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file ../src/libglfw3.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [examples/wave.app/Contents/MacOS/wave] Error 1
make[1]: *** [examples/CMakeFiles/wave.dir/all] Error 2
make: *** [all] Error 2
I look at the failing Makefile in glfw/cmake-build-debug/examples/CMakeFiles/wave.dir/build.make and see the line, where cmake is crashing:
cd /Users/me/Documents/Projects/open-source/glfw/cmake-build-debug/examples && $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/wave.dir/link.txt --verbose=$(VERBOSE)
I manually open the file glfw/cmake-build-debug/examples/CMakeFiles/wave.dir/link.txt file and see the following link script code there:
/Library/Developer/CommandLineTools/usr/bin/cc -g -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/wave.dir/wave.c.o -o wave.app/Contents/MacOS/wave ../src/libglfw3.a -framework Cocoa -framework IOKit -framework CoreFoundation
If I manually execute this line from shell, it successfully builds my binary for arm64 architecture, as expected.
But when this link.txt script is automatically invoked with cmake via cmake -E cmake_link_script CMakeFiles/wave.dir/link.txt --verbose=$(VERBOSE), it fails, apparently, trying to build the binary for the wrong x86_64 architecture.
Why is this happening and how to fix this?
For anyone running into the same problem, it looks like the first version of cmake with an adequate support for Apple Silicon is 3.19.
I was using 3.17.5 as my slightly out-of-date version of CLion does not support versions of cmake above that.
After an update to cmake 3.22.4 the problem is gone.
I'm using a library that I cannot compile for Apple M1, so I have decided to compile it and use it using (Rosetta 2) for x86_64 which I successfully did following this to install brew and clang for x86_64.
However when I compile my project and try to link it against this library I get this error:
ld: warning: ignoring file ..../libapronxx.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
...
ld: symbol(s) not found for architecture arm64
I have tried to the set compiler and linker flags ("-arch x86_64") but still got the same problem.
My question is: What is the proper way to build for macOS-x86_64 using cmake on Apple M1 (arm)?
Additional information: I'm using cmake via CLion.
UPDATE:
I successfully compiled my project using the following commands:
# install a x86 cmake
arch -x86_64 /usr/local/bin/brew install cmake
...
# in the build directory
arch -x86_64 /usr/local/bin/cmake ..
make
arch -x86_64 ./my_exe
I also specified the architecture for clang using -arch flag
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -arch x86_64 -O3")
string(APPEND CMAKE_CC_FLAGS_RELEASE " -arch x86_64 -O3")
# did the same for debug too
While this work fine, I still don't believe it is the proper way to use cmake to build for macOS-x86_64, in fact I cannot take the advantages of my IDE with all this manual approach.
After checking CMake source code, I found that it is enough to set CMAKE_OSX_ARCHITECTURES to x86_64:
set(CMAKE_OSX_ARCHITECTURES "x86_64")
This is the cleanest way so far to solve this issue, and work straight forward with CLion too.
while building my Qt project, an iOS app, I'm getting a symbols not found error for a missing architecture (i386).
The project uses subdirs which again contain 2 self written libraries and an app which links to them.
After some investigating I found out that my libraries use armv7 and arm64 while my app uses i386. What I'm getting from this is that the linker doesn't seem to find the libraries with their respective architectures.
This is what I get from the compiler while building:
ld: warning: ld: warning: ignoring file /Users/me/myprojects/build-myproject-iphonesimulator_clang_Qt_5_7_1_for_iOS-Release/install/lib/libwebdav.a, missing required architecture i386 in file /Users/me/myprojects/build-myproject-iphonesimulator_clang_Qt_5_7_1_for_iOS-Release/install/lib/libwebdav.a (2 slices)ignoring file /Users/me/myprojects/build-myproject-iphonesimulator_clang_Qt_5_7_1_for_iOS-Release/install/lib/libcommon.a, missing required architecture i386 in file /Users/me/myprojects/build-myproject-iphonesimulator_clang_Qt_5_7_1_for_iOS-Release/install/lib/libcommon.a (2 slices)
Undefined symbols for architecture i386:
"CalendarEvent::staticMetaObject", referenced from:
qt_meta_extradata_QMLEventWrapper in moc_qmleventwrapper.o
int qRegisterMetaType(char const*, CalendarEvent::APM_TYPE*, QtPrivate::MetaTypeDefinedHelper::Defined) && (!(QMetaTypeId2::IsBuiltIn))>::DefinedType) in moc_qmleventwrapper.o
"CalendarEvent::colorHex() const", referenced from:
QMLEventWrapper::color() const in qmleventwrapper.o
...
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
...
** BUILD FAILED **
The following build commands failed:
Ld myproject.build/Release-iphonesimulator/myproject.build/Objects-normal/i386/myproject normal i386
(1 failure)
make[1]: * [xcodebuild-release-iphonesimulator] Error 65
make: * [sub-app-make_first] Error 2
Thanks in advance
You are trying to run it on an simulator, which supports architectures i386/x86_64 (the processor of your computer).
Workaround:
Test on a device instead of the simulator
Solution:
Build all used libraries for i386/x86_64 also.
Turned out it was a bug in qmake.
In a very desperate attempt I installed Qt 5.8.0 and tried compiling again. Worked like a charm.
I was using Qt 5.7.1 before which tried to build the libraries for the iPhone instead of the simulator resulting in the wrong architecture.
See https://bugreports.qt.io/browse/QTBUG-58007
Trying to incorporate Vimeo SDK from github into my iOS project.
Xcode 7.3.1
I have cocoa pods installed and my TestVimeo1 project setup but when I attempt target VIMNetworking, AFNetworking and VIMObjectMapper I must not be going about this correct.
ld: warning: directory not found for option '-L/Users/xxxxx/xcodebuild/_buildoutput/TestVimeo1-fktedyrxeulxmicndbpgghnbdjtn/Build/Products/Debug-iphonesimulator/AFNetworking'
ld: warning: directory not found for option '-L/Users/xxxxx/xcodebuild/_buildoutput/TestVimeo1-fktedyrxeulxmicndbpgghnbdjtn/Build/Products/Debug-iphonesimulator/VIMNetworking'
ld: warning: directory not found for option '-L/Users/xxxxx/xcodebuild/_buildoutput/TestVimeo1-fktedyrxeulxmicndbpgghnbdjtn/Build/Products/Debug-iphonesimulator/VIMObjectMapper'
ld: library not found for -lAFNetworking
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can't find the output directories. Where am I going wrong with setting up the target builds for these git submodules? Thanks!