Hello ! I'm Xavier Jouvenot and in this blog post, we are going to see how to correctly fix an error with undefined "_futimens" symbol in LLVM on OSX.
Self promotion: You can find other articles on my website
Problematic
When integrating the latest version of LLVM with your OSX project, you may have encountered an error like:
Undefined symbols for architecture x86_64:
"_futimens", referenced from:
llvm::sys::fs::setLastModificationAndAccessTime(int, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio>>) in libLLVMSupport.a(Path.cpp.o)
This is a problem you will surely meet when trying to use a llvm imported via brew or macport or even from the GitHub of the LLVM project in your program.
But have no worries, we are going to see how to solve this problem π
Solutions
There are actually two solutions that you can implement to fix this problem.
OSX support and LLVM versions
The recent version of LLVM doesn't have a support for "old" version of OSX, but should be able to be integrated on the modern OSX version, officially supported by OSX (10.13 or later).
So a solution to the problem is to update the version of the LLVM and update the OSX SDK you use in your project to have your project working.
You should at least update your OSX Sdk to the version 10.13, since that, from this version of OSX, the "futimens error" is no longer present.
So, if you no longer need to support OSX 10.12 or older, this is the solution you should implement, as it will be the simplest to implement, and to maintain.
For older OSX SDK
If you need to support version of OSX older than the 10.13, then this is the solution you have to implement, as there is no other available to my knowledge.
And this solution consists in building your LLVM on your own.
This solution may seem a big task and overwhelming, but you can actually do it pretty simply.
Indeed, the LLVM project can be build using cmake command very easily with the following command
cd llvm-project/llvm/build
cmake .. -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=../../../install -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12
cmake --build . --config Release --target install
Even on the latest LLVM release, you can support OSX 10.12 or older because of the variable CMAKE_OSX_DEPLOYMENT_TARGET.
The only inconvinent of this solution, is that generating all the LLVM libraries takes a loooooooong time π
But once done, you can use LLVM without problem on your project without any problem π
Thank you all for reading this article,
And until my next article, have a splendid day π
Top comments (0)