'Strange Link errors on iOS with CMake
I'm linking a CMake generated framework to an iOS test Bundle application, in order to execute the tests contained in the framework over an iOS platform. When building, I have an very strange errors in the link stage:
ld: warning: directory not found for option '-L/Users/fporcarelli/GIT/iOSApp/iGeoMobile/smartsdk-middleware/smartsdk-core/Unit-Tests/iOS/SmartSDK-core-tester/../../build/NavNetwork/smartsdk-core/External/lib'
Undefined symbols for architecture x86_64:
"_strchr", referenced from:
_lprofFindFirstDirSeparator in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
"_open", referenced from:
_lprofOpenFileEx in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
"_uname", referenced from:
_lprofGetHostName in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
"_ftell", referenced from:
_getProfileFileSizeForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_strncpy", referenced from:
_createProfileDir in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofGetHostName in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
"_setenv", referenced from:
_truncateCurrentFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_fwrite", referenced from:
_fileWriter in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_atexit", referenced from:
___llvm_profile_register_write_file_atexit in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
(maybe you meant: ___llvm_profile_register_write_file_atexit)
"_fopen", referenced from:
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_truncateCurrentFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_mmap", referenced from:
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_mmapProfileForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_munmap", referenced from:
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_mmapProfileForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_ftruncate", referenced from:
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_fseek", referenced from:
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_fileWriter in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_getProfileFileSizeForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_fprintf", referenced from:
_parseAndSetFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
___llvm_profile_write_file in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_getProfileFileSizeForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_mmapProfileForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofOpenFileEx in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
...
"_strerror", referenced from:
___llvm_profile_write_file in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_getProfileFileSizeForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_mmapProfileForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_fclose", referenced from:
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_truncateCurrentFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_free", referenced from:
_parseAndSetFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
___llvm_profile_instrument_target_value in libclang_rt.profile_iossim.a(InstrProfilingValue.c.o)
"_strcmp", referenced from:
_parseAndSetFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_fileno", referenced from:
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_mmapProfileForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofLockFileHandle in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
_lprofUnlockFileHandle in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
"_fflush", referenced from:
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_exit", referenced from:
_exitSignalHandler in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_getenv", referenced from:
___llvm_profile_initialize_file in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_parseAndSetFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_truncateCurrentFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofSetupValueProfiler in libclang_rt.profile_iossim.a(InstrProfilingValue.c.o)
"_calloc", referenced from:
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
___llvm_profile_instrument_target_value in libclang_rt.profile_iossim.a(InstrProfilingValue.c.o)
"_sigaction", referenced from:
_lprofInstallSignalHandler in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
"_strdup", referenced from:
_parseAndSetFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_memset", referenced from:
_parseAndSetFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_writeOneValueProfData in libclang_rt.profile_iossim.a(InstrProfilingWriter.c.o)
"_fdopen", referenced from:
_lprofOpenFileEx in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
"_atoi", referenced from:
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofSetupValueProfiler in libclang_rt.profile_iossim.a(InstrProfilingValue.c.o)
"___stderrp", referenced from:
_parseAndSetFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
___llvm_profile_write_file in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_getProfileFileSizeForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_mmapProfileForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofOpenFileEx in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
...
"_snprintf", referenced from:
_getCurFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_parseAndSetFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_strlen", referenced from:
_getCurFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
___llvm_profile_write_file in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_truncateCurrentFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_createProfileDir in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"_fcntl", referenced from:
_lprofLockFileHandle in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
_lprofUnlockFileHandle in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
_lprofOpenFileEx in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
"_mkdir", referenced from:
___llvm_profile_recursive_mkdir in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
(maybe you meant: ___llvm_profile_recursive_mkdir)
"___error", referenced from:
___llvm_profile_write_file in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_writeFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_getProfileFileSizeForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_mmapProfileForMerging in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofLockFileHandle in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
_lprofUnlockFileHandle in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
...
"_getpid", referenced from:
_getCurFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_parseAndSetFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofLockFileHandle in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
_lprofUnlockFileHandle in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
_lprofOpenFileEx in libclang_rt.profile_iossim.a(InstrProfilingUtil.c.o)
"_ftello", referenced from:
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
"__Unwind_Resume", referenced from:
-[SmartSDK_core_tests testALL] in SmartSDK_core_tests.o
"___stack_chk_guard", referenced from:
-[SmartSDK_core_tests testALL] in SmartSDK_core_tests.o
_getCurFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
___llvm_profile_write_file in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_truncateCurrentFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_createProfileDir in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofBufferIOWrite in libclang_rt.profile_iossim.a(InstrProfilingWriter.c.o)
...
"_memcpy", referenced from:
_getCurFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofBufferWriter in libclang_rt.profile_iossim.a(InstrProfilingWriter.c.o)
_lprofBufferIOWrite in libclang_rt.profile_iossim.a(InstrProfilingWriter.c.o)
"___stack_chk_fail", referenced from:
-[SmartSDK_core_tests testALL] in SmartSDK_core_tests.o
_getCurFilename in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
___llvm_profile_write_file in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_truncateCurrentFile in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_initializeProfileForContinuousMode in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_createProfileDir in libclang_rt.profile_iossim.a(InstrProfilingFile.c.o)
_lprofBufferIOWrite in libclang_rt.profile_iossim.a(InstrProfilingWriter.c.o)
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The error is very strange, since the unresolved symbols do not belong to my code, but to clang-related static libraries... Thanks in advance for any help
Solution 1:[1]
I found the issue. One of the CMake targets in my framework was named "System". So, the correspondent output file was a "libSystem.a" static library. Swift framework must link to every target an homonym library which contains all standard libraries. For some reasons, the linker found my library in place of the correct one, and so every framework was not able to find the symbols defined in standard libraries (since they are not defined in my System lib).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | alfonsostocchetti |
