当我将资源文件添加到MACOSX应用程序包时,链接器会由于其.obj
后缀而占用它。链接器尝试链接它但没有成功。他写了一个警告:
Linking CXX executable mwe.app/Contents/MacOS/mwe
ld: warning: ignoring file ../star.obj, file was built for unsupported file format
( 0x23 0x20 0x42 0x6C 0x65 0x6E 0x64 0x65 0x72 0x20 0x76 0x32 0x2E 0x37 0x30 0x20 )
which is not the architecture being linked (x86_64): ../star.obj
当然他无法链接,因为star.obj
是obj format中的3D模型文本文件:
# Blender v2.70 (sub 0) OBJ File: 'star.blend'
o Plane
v 0.510396 -0.000389 0.998397
v -0.926169 -0.000017 -0.001603
v 0.510396 0.000355 -1.001603
[..and many more vertices]
由此产生的问题是;该文件未放入MACOSX包文件夹,因为链接器忽略它。
VisorZ@Mac ~/MWE> ll build/mwe.app/Contents/Resources/
total 8
-rw-r--r-- 1 Stephan staff 62B 6 Aug 22:36 star.off
(请参阅此处遗漏star.obj
)----------------------------------- - ^
但源文件属性
也不是目标属性
可以做到这一点。这是一个最小工作示例CMakeLists.txt:
# Minimum Working Example to create mwe.app on MACOSX with linker
# trying to process *.obj files which are marked as resource files
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(mwe)
SET_SOURCE_FILES_PROPERTIES(
star.obj # 3D model as OBJ txt file
star.off # 3D model as OFF txt file
PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)
ADD_EXECUTABLE(
${PROJECT_NAME}
MACOSX_BUNDLE # needs to be second argument, enables bundling
helloworld.cpp # will be compiled
star.obj # will not be bundled because it will be taken by linker
star.off # will be bundled
)
答案 0 :(得分:4)
使用HEADER_FILE_ONLY
并尽量不要过多考虑它的名称。
set_source_files_properties(
star.obj # 3D model as OBJ txt file
star.off # 3D model as OFF txt file
PROPERTIES
HEADER_FILE_ONLY ON
)
答案 1 :(得分:0)
如果要阻止链接器尝试链接文件,可以将它们添加到自定义目标中:
ADD_CUSTOM_TARGET (testTarget SOURCES myFile.obj myFile.off)
这对于在项目树中显示文件但没有编译/链接文件特别方便。