2017-02-05 2 views
0

게임을 만들기 위해 SDL 및 C++을 사용하려고합니다.g ++ 타사 라이브러리를 연결하지 않습니다.

지금까지는 아무 것도 할 수 없었습니다. 나는 Mac 용 지침 (Mac v. 10.12.2)과 http://www.lazyfoo.net/tutorials/SDL/01_hello_SDL/index.php에 g ++를 모두 따라 갔다.

지금은 -l (소문자 L) 옵션으로 지정된 라이브러리를 찾을 수 없다는 링커 오류가 있습니다. 여기 내 Makefile이 있습니다 :

CC = g++ 
CFLAGS = -g -Wall -std=c++11 

SDL_PATH = /Users/myname/Documents/Code-Libraries/SDL2-2.0.5 
SDL_INCLUDE = -I$(SDL_PATH)/include 
SDL_LIB = -L$(SDL_PATH) -l/usr/local/lib/libSDL2.a 

default: SDL01 

SDL01: 01_hello_SDL.cpp 
    $(CC) $(CFLAGS) 01_hello_SDL.cpp $(SDL_LIB) $(SDL_INCLUDE) -o SDL01 

clean: 
    rm -f SDL01 *.o 

나는 -lSDL2를 시도했습니다. 나는 -SIL을 시도했다. 나는 -l/usr/local/lib/libSDL2.a를 시도했다. 나는 다양한 방법으로 -L 옵션 (-l 옵션 없음)을 시도했다. /Users/myname/Documents/Code-Libraries/SDL2-2.0.5 그리고이 하나 (/ Users/myname/Documents/Code-Libraries 다른 사람들은 그들이 프로젝트의 헤더를 찾을 수 없습니다 얘기하면서 /SDL2-2.0.5는) ... ...

Undefined symbols for architecture x86_64: 
    "_SDL_CreateWindow", referenced from: 
     _main in 01_hello_SDL-f65b5c.o 
    "_SDL_Delay", referenced from: 
     _main in 01_hello_SDL-f65b5c.o 
    "_SDL_DestroyWindow", referenced from: 
     _main in 01_hello_SDL-f65b5c.o 
    "_SDL_FillRect", referenced from: 
     _main in 01_hello_SDL-f65b5c.o 
    "_SDL_GetError", referenced from: 
     _main in 01_hello_SDL-f65b5c.o 
    "_SDL_GetWindowSurface", referenced from: 
     _main in 01_hello_SDL-f65b5c.o 
    "_SDL_Init", referenced from: 
     _main in 01_hello_SDL-f65b5c.o 
    "_SDL_MapRGB", referenced from: 
     _main in 01_hello_SDL-f65b5c.o 
    "_SDL_Quit", referenced from: 
     _main in 01_hello_SDL-f65b5c.o 
    "_SDL_UpdateWindowSurface", referenced from: 
     _main in 01_hello_SDL-f65b5c.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make: *** [SDL01] Error 1 

을 나에게 주었다. 나는 정말로 잃어버린 일부 도움을 정말 사랑합니다. 고맙습니다.

EDIT1 :

이이 파일을 /를 ~/문서의 디렉토리입니다/코드 라이브러리/SDL2- : 나는 nm /usr/local/lib/libSDL2.a | grep _SDL_CreateWindow를하고

0000000000001cb0 T _SDL_CreateWindow 
0000000000000f80 T _SDL_CreateWindowAndRenderer 
0000000000007620 t _SDL_CreateWindowAndRenderer_DEFAULT 
       U _SDL_CreateWindowAndRenderer_REAL 
0000000000001cc0 T _SDL_CreateWindowFrom 
0000000000009e80 t _SDL_CreateWindowFrom_DEFAULT 
       U _SDL_CreateWindowFrom_REAL 
0000000000009e30 t _SDL_CreateWindow_DEFAULT 
       U _SDL_CreateWindow_REAL 
0000000000000060 T _SDL_CreateWindowAndRenderer_REAL 
       U _SDL_CreateWindow_REAL 
       U _SDL_CreateWindow_REAL 
00000000000030a0 T _SDL_CreateWindowFrom_REAL 
0000000000000760 t _SDL_CreateWindowTexture 
0000000000002010 T _SDL_CreateWindow_REAL 
       U _SDL_CreateWindow_REAL 

EDIT2있어

2.0.5/디렉토리 :

Android.mk    SDL2.spec.in    cmake_uninstall.cmake.in 
BUGS.txt     TODO.txt     configure 
CMakeLists.txt   VisualC/     configure.in 
COPYING.txt    VisualC-WinRT/   debian/ 
CREDITS.txt    VisualC.html    docs/ 
INSTALL.txt    WhatsNew.txt    include/ 
Makefile.in    Xcode/     sdl2-config.cmake.in 
Makefile.minimal   Xcode-iOS/    sdl2-config.in 
Makefile.pandora   acinclude/    sdl2.m4 
Makefile.psp    android-project/   sdl2.pc.in 
Makefile.wiz    autogen.sh    src/ 
README-SDL.txt   build/     test/ 
README.txt    build-scripts/    
SDL2.spec     cmake/      
+0

여기의 구문은'-l/usr/local/lib/libSDL2.a'가 아닌'-lSDL2' 또는'/ usr/local/lib/libSDL2.a'이어야합니다. – nos

+0

@nos 설명 할 수 있습니까? 나는 g ++가 /usr/local/lib/libSDL2.a를 링크하려고하는 라이브러리로 이해하는 방법을 이해하지 못합니다. 그것은 * .a이기 때문입니까? – astrocat1997

+0

@nos도 작동하지 않았다 :-(. 정크가 많은'Undefined symbols for architecture x86_64 :'가있다. – astrocat1997

답변

1

그래, @ 존 틴크 덕분에, 내가 뭘 잘못하고 있는지 알 수 있었다. 써드 파티 라이브러리가 있던 g ++ 컴파일러에게 컴파일 할 때, 나는 틀린 곳 (-L/Users/myname/Documents/Code-Libraries/SDL2-2.0.5)과 그것에 아무런 의미가없는 이름 (-lSDL2)을주고 있었다. 그래서 여기에 몇 가지 추가 읽기를하고는 https://linux.die.net/man/1/g++에서 몇 가지 중요한 인용은 다음과 같습니다

당신은 옵션과 다른 인수를 혼합 할 수 있습니다. 대부분의 경우, 사용하는 순서는 중요하지 않습니다. 같은 종류의 여러 옵션을 사용할 때 순서가 중요합니다. 예를 들어, -L을 두 번 이상 지정하면 지정한 순서대로 디렉토리가 검색됩니다. 또한 -l 옵션의 배치가 중요합니다.

링커 옵션

객체 파일 이름 -llibrary -nostartfiles -nodefaultlibs -nostdlib -pie -rdynamic -s -static -static-관하여 libgcc는 -shared-관하여 libgcc -symbolic -T 스크립트를 -shared -Wl 옵션 -Xlinker 옵션 -u 기호

디렉토리 옵션

-Bprefix -Idir -iquotedir -Ldir -specs = 파일 -I- --sysroot = DIR

기본적으로 -L 디렉토리 라이브러리이 필요합니다. -L 옵션은 g ++에게 라이브러리를 찾을 위치를 알려주고 -l 옵션은 어떤 라이브러리인지 알려주기 때문입니다. -l 앞에 -L이 없으면 g ++은 -l에서 라이브러리를 찾을 위치를 모른다.

내가 틀렸다면 언제든지 저를 고쳐주십시오! 그러나 이것은 나의 문제를 해결했다.

관련 문제