我对 cmake 很陌生,我正在尝试为 ARM Linux (Android) 交叉编译 libftdi。
为什么 cmake 在 gcc 命令行中添加“-compatibility_version”会导致错误:
/softdev/arm-toolchain/bin/arm-linux-androideabi-gcc -O2 -g -DNDEBUG -dynamiclib -Wl,-headerpad_max_install_names -L/softdev/arm-libs/lib -compatibility_version 2.0.0 -current_version 2.0.0 -o libftdi1.2.0.0.dylib -install_name /Users/asmirnov/Documents/dev/src/libftdi-1.0/src/libftdi1.2.dylib CMakeFiles/ftdi1.dir/ftdi.c.o CMakeFiles/ftdi1.dir/ftdi_stream.c.o /usr/local/lib/libusb-1.0.dylib
arm-linux-androideabi-gcc: error: 2.0.0: No such file or directory
arm-linux-androideabi-gcc: error: 2.0.0: No such file or directory
arm-linux-androideabi-gcc: error: /Users/asmirnov/Documents/dev/src/libftdi-1.0/src/libftdi1.2.dylib: No such file or directory
arm-linux-androideabi-gcc: error: unrecognized option '-compatibility_version'
arm-linux-androideabi-gcc: error: unrecognized option '-current_version'
make[2]: *** [src/libftdi1.2.0.0.dylib] Error 1
make[1]: *** [src/CMakeFiles/ftdi1.dir/all] Error 2
make: *** [all] Error 2
由于我在 gcc参数列表支持的“compatibility_version”命令行参数中找不到是 cmake 错误还是 cmake 配置问题?
更新:问题 #1 已解决(被黑)
我通过在 ../Modules/Platforms/Darwin.cmake 中注释下一行解决了这个问题:
# 4ntoine (fix for libftdi compilation using cmake)
#set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
#set(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
#set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
#set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
# ...
# 4ntoine (fix for libftdi build using cmake)
#if(NOT XCODE)
# Enable shared library versioning. This flag is not actually referenced
# but the fact that the setting exists will cause the generators to support
# soname computation.
# set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name")
#endif()
我知道这不好,尤其是当您不确定自己在做什么时;)
现在我有另一个问题#2:
cd /Users/asmirnov/Documents/dev/src/libftdi-1.0/build/src && /usr/local/Cellar/cmake/2.8.11.1/bin/cmake -E cmake_link_script CMakeFiles/ftdi1.dir/link.txt --verbose=1
/softdev/arm-toolchain/bin/arm-linux-androideabi-gcc -O2 -g -DNDEBUG -dynamiclib -Wl,-headerpad_max_install_names -L/softdev/arm-libs/lib -o libftdi1.dylib CMakeFiles/ftdi1.dir/ftdi.c.o CMakeFiles/ftdi1.dir/ftdi_stream.c.o /softdev/arm-libs/lib/libusb-1.0.so
/softdev/arm-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /softdev/arm-toolchain/bin/../sysroot/usr/lib/crtbegin_dynamic.o: in function _start:crtbrand.c(.text+0x78): error: undefined reference to 'main'
collect2: ld returned 1 exit status
make[2]: *** [src/libftdi1.dylib] Error 1
make[1]: *** [src/CMakeFiles/ftdi1.dir/all] Error 2
make: *** [all] Error 2