使用 clang/LLVM 通过 LDFLAGS 链接 .dylib
linking .dylib via LDFLAGS using clang/LLVM
我收到一个错误。
其中一个源文件引用:
#include <libxml/parser.h>
我正在使用下面的 Makefile,尝试链接:
LDFLAGS =-l../../usr/local/sys/usr/lib/libxml2.dylib
路径似乎正确,并且文件在那里。
来自 IDE 的错误详细信息:http://clip2net.com/clip/m0/1333837472-clip-29kb.pnghttp://clip2net.com/clip/m0/1333837744-clip-32kb.png
我做错了什么?
#############################################################################
# Makefile for iPhone application (X)
#############################################################################
# Define here the name of your project's main executable, and the name of the
# build directory where the generated binaries and resources will go.
NAME = X
OUTDIR = X.app
# Define here the minimal iOS version's MAJOR number (iOS3, iOS4 or iOS5)
IOSMINVER = 5
# List here your project's resource files. They can be files or directories.
RES = Info.plist icon.png
# Define here the compile options and the linker options for your project.
CFLAGS = -W -Wall -O2 -Icocos2dx/include -Icocos2dx/platform -Icocos2dx/platform/ios -Icocos2dx/effects -Icocos2dx/cocoa -Icocos2dx/support -Icocos2dx/support/image_support -Icocos2dx/support/data_support -Icocos2dx/support/zip_support -Icocos2dx/extensions -Icocos2dx
LDFLAGS =-l../../usr/local/sys/usr/lib/libxml2.2.dylib
#############################################################################
# Except for specific projects, you shouldn't need to change anything below
#############################################################################
# Define which compiler to use and what are the mandatory compiler and linker
# options to build stuff for iOS. Here, use the ARM cross-compiler for iOS,
# define IPHONE globally and link against all available frameworks.
CC = clang
LD = link
CFLAGS += -ccc-host-triple arm-apple-darwin -march=armv6 --sysroot ../../usr/local/sys -integrated-as -fdiagnostics-format=msvc -fconstant-cfstrings -DIPHONE -D__IPHONE_OS_VERSION_MIN_REQUIRED=$(IOSMINVER)0000
LDFLAGS += -lstdc++ $(addprefix -framework , $(notdir $(basename $(wildcard /Frameworks/iOS$(IOSMINVER)/*))))
# List here your source files. The current rule means: ask the shell to build
# a one-liner list of all files in the current directory and its subdirectories
# ending with either .c, .cc, .cpp, .cxx, .m, .mm, .mx or .mxx.
SRC = $(shell find . ( -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.m" -o -name "*.mm" -o -name "*.mx" -o -name "*.mxx" ) -printf '%p ')
# Define where the object files should go - currently, just aside the source
# files themselves. We take the source file's basename and just append .o.
OBJ = $(addsuffix .o, $(basename $(SRC)))
###################
# Rules definitions
# This rule is the default rule that is called when you type "make". It runs
# the specified other rules in that order: removing generated output from
# previous builds, compiling all source files into object files, linking them
# all together, codesigning the generated file, copying resources in place
# and then displaying a success message.
all: prune $(OBJ) link codesign resources checksum ipa deb end
# The following rule removes the generated output from any previous builds
prune:
@echo " + Pruning compilation results..."
@rm -f $(OUTDIR)/$(NAME)
# The following rules compile any .c/.cc/.cpp/.cxx/.m/.mm/.mx/.mxx file it
# finds in object files (.o). This is to handle source files in different
# languages: C/C++ (with .c* extension), and Objective-C (.m*).
%.o: %.c
@echo " + Compiling $<..."; $(CC) $(CFLAGS) -o $@ -c $<
%.o: %.cc
@echo " + Compiling $<..."; $(CC) $(CFLAGS) -o $@ -c $<
%.o: %.cpp
@echo " + Compiling $<..."; $(CC) $(CFLAGS) -o $@ -c $<
%.o: %.cxx
@echo " + Compiling $<..."; $(CC) $(CFLAGS) -o $@ -c $<
%.o: %.m
@echo " + Compiling $<..."; $(CC) $(CFLAGS) -o $@ -c $<
%.o: %.mm
@echo " + Compiling $<..."; $(CC) $(CFLAGS) -o $@ -c $<
%.o: %.mx
@echo " + Compiling $<..."; $(CC) $(CFLAGS) -o $@ -c $<
%.o: %.mxx
@echo " + Compiling $<..."; $(CC) $(CFLAGS) -o $@ -c $<
# The following rule first ensures the output directory exists, creates it if
# necessary, then links the compiled .o files together in that directory
link:
@echo " + Linking project files..."
@test -d $(OUTDIR) || mkdir -p $(OUTDIR)
@$(LD) $(LDFLAGS) -o $(OUTDIR)/$(NAME) $(OBJ)
# The following rule calls Saurik's ldid code pseudo-signing tool to generate
# the SHA checksums needed for the generated binary to run on jailbroken iOS.
codesign:
@echo " + Pseudo-signing code..."
@ldid -S $(OUTDIR)/$(NAME)
@rm -f $(OUTDIR)/.$(NAME).cs
# The following rule takes all the specified resource items one after the
# other (whether they are files or directories) ; files are copied in place
# and directories are recursively copied only if they don't exist already.
resources:
@echo " + Copying resources..."
@for item in $(RES); do
if [ -d $$item ]; then test -d $(OUTDIR)/$$item || cp -r $$item $(OUTDIR)/; chmod +r $(OUTDIR)/$$item;
else cp $$item $(OUTDIR)/; chmod +r $(OUTDIR)/$$item;
fi;
done
@chmod +x $(OUTDIR)
@chmod -R +r $(OUTDIR)
@chmod +x $(OUTDIR)/$(NAME)
# The following rule takes all files in the target directory and builds the
# _CodeSignature/CodeResource XML file with their SHA1 hashes.
checksum:
@echo " + Generating _CodeSignature directory..."
@echo -n APPL???? > $(OUTDIR)/PkgInfo
@codesigner $(OUTDIR) > .CodeResources.$(NAME)
@test -d $(OUTDIR)/_CodeSignature || mkdir -p $(OUTDIR)/_CodeSignature
@mv .CodeResources.$(NAME) $(OUTDIR)/_CodeSignature/CodeResources
@test -L $(OUTDIR)/CodeResources || ln -s _CodeSignature/CodeResources $(OUTDIR)/CodeResources
# The following rule builds an IPA file out of the compiled app directory.
ipa:
@echo " + Building iTunes package..."
@test -d Packages || mkdir Packages
@rm -f Packages/$(NAME).ipa
@test -d Payload || mkdir Payload
@mv -f $(OUTDIR) Payload
@cp -f iTunesArtwork.jpg iTunesArtwork
@chmod +r iTunesArtwork
@zip -y -r Packages/$(NAME).ipa Payload iTunesArtwork -x *.log *.lastbuildstate *successfulbuild > /dev/null
@rm -f iTunesArtwork
@mv -f Payload/$(OUTDIR) .
@rmdir Payload
# The following rule builds a Cydia package out of the compiled app directory.
deb:
@echo " + Building Cydia package..."
@test -d Packages || mkdir Packages
@rm -f Packages/$(NAME).deb
@test -d $(NAME) || mkdir $(NAME)
@test -d $(NAME)/Applications || mkdir $(NAME)/Applications
@mv -f $(OUTDIR) $(NAME)/Applications
@test -d $(NAME)/DEBIAN || mkdir $(NAME)/DEBIAN
@cp -f cydia-package.cfg $(NAME)/DEBIAN/control
@chmod +r $(NAME)/DEBIAN/control
@echo "#!/bin/bash" > $(NAME)/DEBIAN/postinst
@echo "rm -f /Applications/$(OUTDIR)/*.log /Applications/$(OUTDIR)/*.lastbuildstate /Applications/$(OUTDIR)/*.successfulbuild" >> $(NAME)/DEBIAN/postinst
@echo "chown -R root:admin "/Applications/$(OUTDIR)"" >> $(NAME)/DEBIAN/postinst
@echo "find "/Applications/$(OUTDIR)"|while read ITEM; do if [ -d "$$ITEM" ]; then chmod 755 "$$ITEM"; else chmod 644 "$$ITEM"; fi; done" >> $(NAME)/DEBIAN/postinst
@echo "chmod +x "/Applications/$(OUTDIR)/$(NAME)"" >> $(NAME)/DEBIAN/postinst
@echo "su -c /usr/bin/uicache mobile 2> /dev/null" >> $(NAME)/DEBIAN/postinst
@echo "exit 0" >> $(NAME)/DEBIAN/postinst
@chmod +r+x $(NAME)/DEBIAN/postinst
@dpkg-deb -b $(NAME) > /dev/null 2>&1
@mv -f $(NAME).deb Packages
@mv -f $(NAME)/Applications/$(OUTDIR) .
@rm -rf $(NAME)
# This simple rule displays the success message after a successful build
end:
@echo " + Done. Output directory is "$(OUTDIR)", iTunes package is "Packages$(NAME).ipa", Cydia package is "Packages$(NAME).deb"."
# This rule removes generated object files from the project and also temporary
# files ending with ~ or #.
clean:
@echo " + Cleaning project intermediate files..."
@rm -f $(OBJ) *~ *#
@echo " + Done."
# This rule removes all generated output from any previous builds so as to
# leave an intact source tree (useful for generating source tree releases).
distclean: clean
@echo " + Cleaning project output files..."
@rm -rf $(OUTDIR)
@echo " + Done."
实际上,您可能有两个问题。我建议你试试:
将-I../../usr/local/sys/usr/include
添加到 CFLAGS 以使其找到标头。
将LDFLAGS
更改为 -L../../usr/local/sys/usr/lib
,添加LIBS=-lxml2
并将链接器调用更改为$(LD) $(LDFLAGS) -o $(OUTDIR)/$(NAME) $(OBJ) $(LIBS)
(即在链接器命令行的末尾添加-l
,在链接器命令行的开头添加-L
)。
-l 仅用于指定库名称。使用 -L 添加还将在其中查找库的目录:
LDFLAGS += -L../../usr/local/sys/usr/lib -lxml2
希望这有帮助。
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- CMake-按正确顺序将项目与C运行时对象文件链接
- 从链接列表c++中删除一个项目
- 有根的二进制搜索树.保留与其父级的链接
- 读取文件的最后一行并输入到链接列表时出错
- 静态数据成员的问题-修复链接错误会导致编译器错误
- node-gyp 在 macOS 上未正确链接库
- 基于boost的程序的静态链接——zlib问题
- 无法链接 CMake 中的本地库
- 内联函数中具有内部链接的全局变量
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 使用gcc从静态链接的文件中查找可选符号
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 下面是我为检测链接列表中的循环而制作的代码
- 有了gcc,是否可以链接库,但前提是它存在
- 使用C链接在函数内部创建C++模板
- Visual Studio mkl_link_tool.exe链接错误
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- 使用 clang/LLVM 通过 LDFLAGS 链接 .dylib