使用带Xcode 4的allegro

时间:2011-03-13 09:13:41

标签: xcode xcode4 allegro

我正在尝试使用Xcode 4构建一个简单的allegro项目。

#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, char **argv)
{
    ALLEGRO_DISPLAY *display = NULL;

    if(!al_init()) {
        fprintf(stderr, "failed to initialize allegro!\n");
        return -1;
    }

    display = al_create_display(640, 480);
    if(!display) {
        fprintf(stderr, "failed to create display!\n");
        return -1;
    }

    al_clear_to_color(al_map_rgb(0,0,0));

    al_flip_display();

    al_rest(10.0);

    al_destroy_display(display);

    return 0;
}

我可以使用以下命令从终端构建它,但在Xcode 4中我没有运气。我没有Xcode 3再试一次。 = \

gcc alleg5test.c -o alleg5test -L/usr/local/lib -lallegro -lallegro_main

我的Xcode 4项目是使用控制台应用程序模板创建的。 对构建设置进行了以下更改

标题搜索路径 / usr / local / include
图书馆搜索路径 / usr / local / lib
其他链接标记 -framework Cocoa -lallegro -lallegro_main

当我尝试从Xcode构建项目时出现以下错误

Build target Test of project Test with configuration Debug

CompileC /Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Intermediates/Test.build/Debug/Test.build/Objects-normal/i386/main.o Test/main.cpp normal i386 c++ com.apple.compilers.gcc.4_2
cd /Users/zrbecker/Documents/Programming/Test
setenv LANG en_US.US-ASCII
/Developer/usr/bin/gcc-4.2 -x c++ -arch i386 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wunused-variable -Wshorten-64-to-32 -DDEBUG -isysroot /Developer/SDKs/MacOSX10.6.sdk -fasm-blocks -mmacosx-version-min=10.6 -gdwarf-2 -fvisibility-inlines-hidden -iquote /Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Intermediates/Test.build/Debug/Test.build/Test-generated-files.hmap -I/Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Intermediates/Test.build/Debug/Test.build/Test-own-target-headers.hmap -I/Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Intermediates/Test.build/Debug/Test.build/Test-all-target-headers.hmap -iquote /Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Intermediates/Test.build/Debug/Test.build/Test-project-headers.hmap -I/Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Products/Debug/include -I/Users/zrbecker/local/include -I/Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Intermediates/Test.build/Debug/Test.build/DerivedSources/i386 -I/Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Intermediates/Test.build/Debug/Test.build/DerivedSources -F/Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Products/Debug -F/Users/zrbecker/Documents/Programming/Test/../../../Library/Frameworks -c /Users/zrbecker/Documents/Programming/Test/Test/main.cpp -o /Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Intermediates/Test.build/Debug/Test.build/Objects-normal/i386/main.o

Ld /Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Products/Debug/Test normal i386
cd /Users/zrbecker/Documents/Programming/Test
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/g++-4.2 -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Products/Debug -L/Users/zrbecker/local/lib -F/Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Products/Debug -F/Users/zrbecker/Documents/Programming/Test/../../../Library/Frameworks -filelist /Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Intermediates/Test.build/Debug/Test.build/Objects-normal/i386/Test.LinkFileList -mmacosx-version-min=10.6 -framework Cocoa -lallegro -lallegro_main -framework OpenGL -o /Users/zrbecker/Library/Developer/Xcode/DerivedData/Test-hbexqsyhqhbcnfdswhkuzhjokkih/Build/Products/Debug/Test

ld: warning: ignoring file /Users/zrbecker/local/lib/liballegro.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/zrbecker/local/lib/liballegro_main.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
"_main", referenced from:
start in crt1.10.6.o
(maybe you meant: __al_mangled_main)
"_al_install_system", referenced from:
__al_mangled_main in main.o
"_al_create_display", referenced from:
__al_mangled_main in main.o
"_al_map_rgb", referenced from:
__al_mangled_main in main.o
"_al_clear_to_color", referenced from:
__al_mangled_main in main.o
"_al_flip_display", referenced from:
__al_mangled_main in main.o
"_al_rest", referenced from:
__al_mangled_main in main.o
"_al_destroy_display", referenced from:
__al_mangled_main in main.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

这条消息似乎暗示我的库编译错了,但就像我说的那样,我从终端编译好了。

我从源头建立了快板。

tar -xzf allegro-5.0.0.tar.gz
cd allegro-5.0.0
mkdir Build
cd Build
cmake ..
make
sudo make install

我也尝试用Clang构建,我在上面添加了这两个命令。

export PATH=/Developer/usr/bin:$PATH
export CC=clang

不确定这是否是有用的信息,但我认为它不会受到伤害。

感谢您的任何建议。

1 个答案:

答案 0 :(得分:3)

这个问题(关于XCode 4)应该在Allegro 5.0.1中修复:

  

在OS X上强制_al_mangled_main的“默认”可见性,否则为   如果使用XCode4构建

,则动态链接器无法找到该符号