问题
I wanted to compile the sample C++ program that uses VLC Api, according to the https://wiki.videolan.org/LibVLC_Tutorial/, with my Visual Studio 2012 on Windows 7 x64 (I work with x86 anyway).
In order to obtain a .lib
file, I've followed: https://wiki.videolan.org/GenerateLibFromDll/. I had some problems at the start, but finally I got (I've noticed the warnings):
And I do have my libvlc.lib
created. I've moved it to the folder with my main.cpp
, added the path to Project -> VC++ Directories -> Library directories
as well as added the .lib
file with Add -> existing item
. I also added the Project -> VC++ Directories -> Include Directories
so it points to ...vlc-2.1.5\include
.
I run the clean, rebuild all
on my empty solution.
Unfortunately I got the errors:
1>------ Rebuild All started: Project: Project1, Configuration: Debug Win32 ------
1> Source.cpp
1>Source.obj : error LNK2019: unresolved external symbol _libvlc_new referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _libvlc_release referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _libvlc_media_new_location referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _libvlc_media_release referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _libvlc_media_player_new_from_media referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _libvlc_media_player_release referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _libvlc_media_player_play referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _libvlc_media_player_stop referenced in function _main
1>...\Project1\Debug\Project1.exe : fatal error LNK1120: 8 unresolved externals
Which looks like either something is wrong with my .lib
or its somehow it's not connected in a right way. The compilation works fine, the linking fails.
The full source code of the only .cpp
file in project is an exact copy of the tutorial posted on videolan.org: http://pastebin.com/5gfFVFZd
edit:
According to @user1
comment, I've corrected the dumpbin
command (in the screen shot, "libvlc.dill" should be "libvlc.dll"). That was indeed one problem. After the change, I got much more warnings (all of the same type as before, 277 together) and much bigger .def file (15MB, progress). But the output .lib file is exact same size (1.48MB - it's very small .lib) and the linker error with it prevails. So I guess there's still something wrong with the .lib creation.
The .def
file: http://pastebin.com/E81s6dnh
The last lines make me feel uncomfortable:
256 FF 00001CF0 libvlc_vprinterr
257 100 00001790 libvlc_wait
LINK : fatal error LNK1328: missing string table
回答1:
Check dumpbin
command in the screen shot,
"libvlc.dill" should be "libvlc.dll"
Generally speaking, when all inputs to linker are correct & yet if linker complains then I would look at some lib import #defines specifically. Sometimes, .lib can't just be imported without defining some #DEFINE in the linker input settings which allows the lib to be imported. e.g. IMPORT_X_LIB. Do you have any such import lib #define defined for vlc lib. if yes, you must add those in linker input.
回答2:
There is an error in the instructions on the Wiki.
(1) You need to install the 32 bit version of VLC, NOT the 64 bit version, by downloading the "Windows" installer from here.
(2) It installs into "C:\Program Files (x86)\" folder, NOT the "C:\Program Files\" folder. Ou need to run all the instructions on the Wiki page with this folder substitute.
(3) Then you need to compile your Visual Studio project as an x86 project.
(4) When you compile, you need to copy the following library files from the folder in (2) above into the Debug/Release directoty in which your executable builds.
libvlc.dll
libvlc.lib
libvlc.exp
(5) In addition to linking to the header file from the source download, you need to add "libvlc.lib" to your project to:
Project-> Properties-> Linker-> Input-> Additional Dependencies
(6) Also add the directory "C:\Program Files (x86)\VideoLAN\VLC" where copies of the 3 library files reside to:
Project-> Properties-> Linker-> General-> Additional Library Directors
(7) Now the program should link and run without the Application error.
The above error happens because:
(i) The program cannot find where the libvlc.lib library is to link to without the VS setting.
(ii) It cannot find the libraries to attach to without the 3 library files being ciopied to the same directory that the project executable builds in.
(iii) When it actually links, the actual DLL in VLC installed to "C:\Program Files\" is the 64 bit version, when the rest of your program is x86.
来源:https://stackoverflow.com/questions/27686332/vlc-api-with-c-linker-error-for-lib-even-when-ive-added-it-to-my-vc-pro