简体   繁体   English

在Eclipse中使用gcc -shared找不到库来构建dll

[英]Cannot find library using gcc -shared in Eclipse to build a dll

I am trying to use the FFMPEG library that I just compiled on Windows using MinGW in a C program in Eclipse. 我正在尝试使用Eclipse的C程序中使用MinGW在Windows上编译的FFMPEG库。 I have managed to build a simple HelloJNI.c file and run it: 我设法建立了一个简单的HelloJNI.c文件并运行它:

gcc $(INCLUDES) -c -g -w HelloJNI.c
gcc -shared -o $(BIN_DIR)/hello.dll HelloJNI.o

I am now trying to compile a ffmpeg_native.c file that uses FFMPEG but I am getting errors running the following: 我现在正在尝试编译使用FFMPEG的ffmpeg_native.c文件,但是运行以下命令时出现错误:

LIBRARY_PATH = -L:"c:/Dev/msys-1.0/local/lib" -L:"c:/Dev/msys-1.0/local"
INCLUDES = -I$(SRC_DIR) -I"c:/Dev/msys-1.0/local/include" -I"c:/Program Files/Java/jdk1.8.0_45/include" -I"c:/Program Files/Java/jdk1.8.0_45//include/win32"
BIN_DIR = ../bin

gcc $(INCLUDES) -c -g -w ffmpeg_native1.1.4.c
gcc -shared -o $(BIN_DIR)/exportnative.dll ffmpeg_native1.1.4.o $(LIBRARY_PATH) -lffmpeg -lavcodec -lx264 -lavformat -lavutil -lswscale

The first line runs fine but the second shows this output: 第一行运行正常,但第二行显示此输出:

c:/Dev/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lavcodec
[etc for all libraries]

I am puzzled as I am able to run the following in MinGW with success: 我很困惑,因为我能够在MinGW中成功运行以下命令:

ld -o /local/libffmpeg.so -L/local/lib -lavcodec -lx264 -lavformat -lavutil -lswscale

It cannot find library path since -L is missing before $(LIBRARY_PATH) . 由于找不到$(LIBRARY_PATH)之前的-L ,因此找不到库路径。 From gcc man: 来自gcc man:

-L dir -L 目录
Add directory dir to the list of directories to be searched for -l . 将目录dir添加到要搜索-l的目录列表中。

So, if LIBRARY_PATH contains directory with needed libraries and everyting other is fine the following should work: 因此,如果LIBRARY_PATH包含具有所需库的目录,并且其他都不错,则应该可以进行以下操作:

gcc -shared -o $(BIN_DIR)/exportnative.dll ffmpeg_native1.1.4.o -L$(LIBRARY_PATH) -lffmpeg -lavcodec -lx264 -lavformat -lavutil -lswscale

It is not needed to put colon : between -L and the path. 不需要在-L和路径之间放置冒号: The following list should be added to the command line: 以下列表应添加到命令行:

-L"c:/Dev/msys-1.0/local/lib" -L"c:/Dev/msys-1.0/local"`

Note that it is better to use some other environment variable name for building the command line, since LIBRARY_PATH is used by gcc directly: 请注意,最好使用其他环境变量名称来构建命令行,因为LIBRARY_PATH由gcc直接使用:

LIBRARY_PATH
The value of LIBRARY_PATH is a colon-separated list of directories, much like PATH . LIBRARY_PATH的值是用冒号分隔的目录列表,非常类似于PATH When configured as a native compiler, GCC tries the directories thus specified when searching for special linker files, if it can't find them using GCC_EXEC_PREFIX . 如果配置为本机编译器,则GCC会在搜索特殊链接器文件时尝试使用这样指定的目录,如果它无法使用GCC_EXEC_PREFIX找到它们。 Linking using GCC also uses these directories when searching for ordinary libraries for the -l option (but directories specified with -L come first). 当在普通库中搜索-l选项时,使用GCC链接也会使用这些目录(但使用-L指定的目录排在最前面)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM