1

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

#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

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

感谢您的任何建议。

4

1 回答 1

3

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

在 OS X 上强制 _al_manangled_main 的“默认”可见性,否则如果使用 XCode4 构建,动态链接器将找不到符号

于 2011-03-14T02:08:44.797 回答