我试图交叉编译我正在做的软件。 我正在使用Linux,而且我很难尝试使用SDL2编写用于编译DLL库的Makefile。这是它:
#the compiler
CC = i686-w64-mingw32-gcc
#the standart ompilation flags of the project
CFLAGS = -O3 -Wall -Wno-unused-variable -Wno-unused-but-set-variable -Wno-implicit-function-declaration
#path to the folder's root, where the holy not build framework is. Relate to this Makefile
PREPATH = ..
#Path to the SDL, SDL_image and Lua includes and libs
SDL2INCLUDES = -I $(PREPATH)/SDL2/include
SDL2LIBS = $(PREPATH)/BINARIES/4windows/SDL2/64/SDL2.dll
SDLIMAGE2INCLUDES = -I $(PREPATH)/SDL2/SDL_image
SDLIMAGE2LIBS = $(PREPATH)/BINARIES/4windows/SDL2_image/64/SDL2_image.dll $(PREPATH)/BINARIES/4windows/SDL2_image/64/libjpeg-9.dll $(PREPATH)/BINARIES/4windows/SDL2_image/64/libpng16-16.dll $(PREPATH)/BINARIES/4windows/SDL2_image/64/libtiff-5.dll $(PREPATH)/BINARIES/4windows/SDL2_image/64/libwebp-4.dll $(PREPATH)/BINARIES/4windows/SDL2_image/64/zlib1.dll
#LUAINCLUDES = -I $(PREPATH)/lua/
#LUALIB = $(PREPATH)/lua/ -llua -lm
#Where to put the compiled program
COMPILEPATH = $(PREPATH)/BINARIES/
#Build options
build: NLF.o
cp ./*.o $(COMPILEPATH)
$(CC) $(CFLAGS) -shared -o $(COMPILEPATH)libNLF.dll $(SDL2LIBS) $(SDLIMAGE2LIBS) $(COMPILEPATH)*.o
NLF.o: NLF_osservice.o NLF_error.o NLF_screen.o NLF.h.gch
$(CC) -c -DBUILD_DLL $(CFLAGS) $(SDL2INCLUDES) $(SDLIMAGE2INCLUDES) NLF.c
NLF.h.gch: NLF.h
$(CC) $(CFLAGS) $(SDL2INCLUDES) $(SDLIMAGE2INCLUDES) NLF.h
NLF_osservice.o: NLF_osservice.h.gch
$(CC) -c -DBUILD_DLL $(CFLAGS) $(SDL2INCLUDES) NLF_osservice.c
NLF_osservice.h.gch:
$(CC) $(CFLAGS) $(SDL2INCLUDES) NLF_osservice.h
NLF_error.o: NLF_error.h.gch
$(CC) -c -DBUILD_DLL $(CFLAGS) $(SDL2INCLUDES) NLF_error.c
NLF_error.h.gch:
$(CC) $(CFLAGS) $(SDL2INCLUDES) NLF_error.h
NLF_screen.o: NLF_screen.h.gch
$(CC) -c -DBUILD_DLL $(CFLAGS) $(SDL2INCLUDES) $(SDLIMAGE2INCLUDES) NLF_screen.c
NLF_screen.h.gch:
$(CC) $(CFLAGS) $(SDL2INCLUDES) $(SDLIMAGE2INCLUDES) NLF_screen.h
#cleaning options
clean-build:
rm -f -v $(COMPILEPATH)*.o
clean-all:
rm -f -v ./*.o ./*.h.gch
rm -f -v $(COMPILEPATH)*.o $(COMPILEPATH)*.so
clean-soft:
rm -f -v ./*.o ./*.h.gch
rm -f -v $(COMPILEPATH)*.o
当运行make all时,编译运行正常,但当它到达-shared
部分时,我得到了这个:
../ BINARIES / 4windows / SDL2 / 64 / SDL2.dll:无法识别文件:
我尝试在第三方DLL之前添加-L
,如下所示:
SDL2LIBS = -L $(PREPATH)/BINARIES/4windows/SDL2/64/SDL2.dll
SDLIMAGE2LIBS = -L $(PREPATH)/BINARIES/4windows/SDL2_image/64/SDL2_image.dll -L $(PREPATH)/BINARIES/4windows/SDL2_image/64/libjpeg-9.dll -L $(PREPATH)/BINARIES/4windows/SDL2_image/64/libpng16-16.dll -L $(PREPATH)/BINARIES/4windows/SDL2_image/64/libtiff-5.dll -L $(PREPATH)/BINARIES/4windows/SDL2_image/64/libwebp-4.dll -L $(PREPATH)/BINARIES/4windows/SDL2_image/64/zlib1.dll
然后我得到未定义的引用错误...... 如果我更改了该行,则会出现同样的错误:
$(CC) $(CFLAGS) -shared -o $(COMPILEPATH)libNLF.dll $(SDL2LIBS) $(SDLIMAGE2LIBS) $(COMPILEPATH)*.o
的
$(CC) $(CFLAGS) $(SDL2LIBS) $(SDLIMAGE2LIBS) -shared -o $(COMPILEPATH)libNLF.dll $(COMPILEPATH)*.o
有谁知道发生了什么?
答案 0 :(得分:1)
您不应在库文件之前使用-L。 -L表示库路径。对于库文件,您应该使用-l(小写L)。 但是,如果您指示文件的路径,并且包含文件扩展名,则不需要使用-l。所以初始Makefile在这个意义上是正确的。
您应该提供完整的错误,而不是just file not recognized:
。我敢打赌这是一个file format not recognized
错误,这可能表示你不应该链接.dll文件,而是.lib文件。 Similar problem here
答案 1 :(得分:0)
我已经解决了!!这是怎么回事 将这些文件放在SDL路径中:
libSDL2.a,libSDL2.dll.a,libSDL2main.a,libSDL2_test.a,SDL2.lib,SDL2main.lib和SDL2test.lib
这些与SDL_image一起。:
libSDL2_image.a和libSDL2_image.dll.a
这是Makefile:
#the compiler
CC = i686-w64-mingw32-gcc
#the standart ompilation flags of the project
CFLAGS = -O3 -Wall -Wno-unused-variable -Wno-unused-but-set-variable -Wno-implicit-function-declaration
#path to the folder's root, where the holy not build framework is. Relate to this Makefile
PREPATH = ..
#Path to the SDL, SDL_image and Lua includes and libs
SDL2INCLUDES = -I $DS(PREPATH)/SDL2/include
SDL2LIBS = -L$(PREPATH)/SDL2/4windows/SDL2/64 -lmingw32 -lSDL2main -lSDL2
SDLIMAGE2INCLUDES = -I $(PREPATH)/SDL2/SDL_image
SDLIMAGE2LIBS = -L$(PREPATH)/SDL2/4windows/SDL2_image/64 -lSDL2_image
#LUAINCLUDES = -I $(PREPATH)/lua/
#LUALIB = -L $(PREPATH)/lua/ -llua -lm
#Where to put the compiled program
COMPILEPATH = $(PREPATH)/BINARIES/
#Build options
build: NLF.o
cp ./*.o $(COMPILEPATH)
$(CC) $(CFLAGS) -shared $(COMPILEPATH)*.o $(SDL2LIBS) $(SDLIMAGE2LIBS) -o $(COMPILEPATH)libNLF.dll
NLF.o: NLF_osservice.o NLF_error.o NLF_screen.o NLF.h.gch
$(CC) -c -DBUILD_DLL $(CFLAGS) $(SDL2INCLUDES) $(SDLIMAGE2INCLUDES) NLF.c
NLF.h.gch: NLF.h
$(CC) $(CFLAGS) $(SDL2INCLUDES) $(SDLIMAGE2INCLUDES) NLF.h
NLF_osservice.o: NLF_osservice.h.gch
$(CC) -c -DBUILD_DLL $(CFLAGS) $(SDL2INCLUDES) NLF_osservice.c
NLF_osservice.h.gch:
$(CC) $(CFLAGS) $(SDL2INCLUDES) NLF_osservice.h
NLF_error.o: NLF_error.h.gch
$(CC) -c -DBUILD_DLL $(CFLAGS) $(SDL2INCLUDES) NLF_error.c
NLF_error.h.gch:
$(CC) $(CFLAGS) $(SDL2INCLUDES) NLF_error.h
NLF_screen.o: NLF_screen.h.gch
$(CC) -c -DBUILD_DLL $(CFLAGS) $(SDL2INCLUDES) $(SDLIMAGE2INCLUDES) NLF_screen.c
NLF_screen.h.gch:
$(CC) $(CFLAGS) $(SDL2INCLUDES) $(SDLIMAGE2INCLUDES) NLF_screen.h
#cleaning options
clean-build:
rm -f -v $(COMPILEPATH)*.o
clean-all:
rm -f -v ./*.o ./*.h.gch
rm -f -v $(COMPILEPATH)*.o $(COMPILEPATH)*.dll
clean-soft:
rm -f -v ./*.o ./*.h.gch
rm -f -v $(COMPILEPATH)*.o
现在我的新问题是如何将所有这些东西编译成32位窗口。但这是另一个问题的陈述。