-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake Interprocedural Optimization (LTO) with static libraries uses the wrong tools #11143
Comments
Seems like the second solution is the more correct one. Do you fancy sending a PR? |
There you go #11161. |
Is this issue still relevant? PR is merged but the issue remains open. I can not currently test it due to regression mentioned in #13067. |
The merged PR fixed the issue and I can say that it still works since then up to 2.0.8 (I didn't test later versions). So this issue could be closed long ago. 👍 |
Strange, it doesn't work for me. I can not build static libraries with LTO. I get |
I just tried with Arch Linux, CMake 3.19.2 and emscripten 2.0.8 with the following project: CMakeLists.txt:
mylib.cpp:
In the source dir :
Does this work for you? Edit: read too fast sorry. So your AR doesn't seem to be detected, strange... |
Added an executable to your example, but still it builds correctly. My project does not - perhaps this example is not complex enough to try to invoke AR program. |
Since recent the CMake cleanup (#10934), CMake uses the system
llvm-ar
instead ofemar
when creating a static library because CMake doesn't seem to honorCMAKE_AR
whenCMAKE_INTERPROCEDURAL_OPTIMIZATION
is set toTRUE
. Instead, it usesCMAKE_C_COMPILER_AR
orCMAKE_CXX_COMPILER_AR
defined by CMake compilator modules.Example (tested on Ubuntu 19.10 and Arch Linux)
CMakeLists.txt
:lib.cpp
is an empty file.llvm
is installed on the system,CMakeCache.txt
contains :and the compilation finishes without error but if we run
emmake make VERBOSE=1
, we can see that it uses the systemllvm-ar
andllvm-ranlib
.llvm
is not installed,CMakeCache.txt
contains :and there is an error when linking
liblib.a
.emmake make VERBOSE=1
tells us :Suggestion
One of these should work :
cmake/Modules/Platform/Emscripten.cmake
from A couple of cmake cleanups. NFC. #10934 :The linking command become :
"[some_path]/emsdk/upstream/emscripten/emar" rc liblib.a @CMakeFiles/lib.dir/objects1.rsp
for both non-IPO and IPO build.cmake/Modules/Platform/Emscripten.cmake
(somewhere afterCMAKE_AR
andCMAKE_RANLIB
definitions) :The linking commands become :
for both non-IPO and IPO build.
I think the second solution is better because without IPO, CMake runs both
ar
andranlib
and this solution tells CMake to specifically use emscripten'sar
andranlib
tool for any purpose and not only static linking. (I don't really have knowledge in the linking process so maybe justar
only is better in this case, feel free to correct me if I'm wrong.)The text was updated successfully, but these errors were encountered: