开发者

Using allegro with Xcode 4

I am trying to build a simple allegro project with 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;
}

I can build an run it from the terminal using the following command, but in Xcode 4 I have had no luck. I don't have Xcode 3 to try anymore. =\

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

My Xcode 4 project is created using the console application template. The following changes were made to the build settings

Header Search Paths /usr/local/include

Library Search Paths /usr/local/lib

Other Linker Flags -framework Cocoa -lallegro -lallegro_main

I get the following errors when I try to build the project from 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-hbexq开发者_StackOverflowsyhqhbcnfdswhkuzhjokkih/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

This message seems to be suggesting that I have my libraries compiled wrong, but like I said, I compiled fine from the terminal.

I built allegro from source.

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

I also tried building with Clang where I added these two command before the above.

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

Not sure if that is helpful information, but I assume it couldn't hurt.

Thanks for any advice.


This problem (regarding XCode 4) should be fixed in Allegro 5.0.1:

Force "default" visibility of _al_mangled_main on OS X, otherwise the dynamic linker cannot find the symbol if building with XCode4

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜