使用clang / LLVM通过LDFLAGS连接.dylib [英] linking .dylib via LDFLAGS using clang/LLVM

查看:360
本文介绍了使用clang / LLVM通过LDFLAGS连接.dylib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误。

其中一个来源档案参考资料:

One of the source files references:

#include <libxml/parser.h>

我正在使用下面的Makefile,尝试链接:

I am working with a Makefile below, trying to link:

LDFLAGS =-l../../usr/local/sys/usr/lib/libxml2.dylib

路径显示正确,并且文件在那里。

Path appears to be correct, and the file is there.

IDE中的错误详细信息:
http://clip2net.com/clip/m0/1333837472-clip- 29kb.png
http://clip2net.com/ clip / m0 / 1333837744-clip-32kb.png

Error details from IDE: http://clip2net.com/clip/m0/1333837472-clip-29kb.png http://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."


推荐答案

你实际上可能有两个问题。我建议你尝试:

You actually may have two problems. I suggest you try:

添加 -I ../../ usr / local / sys / usr / include

Add -I../../usr/local/sys/usr/include to your CFLAGS to make it find the header.

更改 LDFLAGS - L ../../ usr / local / sys / usr / lib ,添加 LIBS = -lxml2 ,并将链接器调用更改为 $(LD)$(LDFLAGS)-o $(OUTDIR)/ $(NAME)$(OBJ)$(LIBS)(即添加 -l ,在链接器命令行开头的 -L )。

Change the LDFLAGS to -L../../usr/local/sys/usr/lib, add LIBS=-lxml2 and change the linker invocation to $(LD) $(LDFLAGS) -o $(OUTDIR)/$(NAME) $(OBJ) $(LIBS) (i.e. add the -l at the end, the -L at the beginning of the linker command line).

这篇关于使用clang / LLVM通过LDFLAGS连接.dylib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆