Unresolved external symbol when linking ffmpeg/avcodec with Visual Studio 2015? - visual-studio

I'm trying to build ffmpeg/avcodec library with Visual Studio 2015 and it gives me following linking error:
allcodecs.obj : error LNK2001: unresolved external symbol ff_h263_vaapi_hwaccel
allcodecs.obj : error LNK2001: unresolved external symbol ff_h263_vdpau_hwaccel
allcodecs.obj : error LNK2001: unresolved external symbol ff_h263_videotoolbox_hwaccel
...
The problem comes from this macro https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/allcodecs.c#L34
#include "config.h"
#include "avcodec.h"
#include "version.h"
...
#define REGISTER_HWACCEL(X, x) \
{ \
extern AVHWAccel ff_##x##_hwaccel; \
if (CONFIG_##X##_HWACCEL) \
av_register_hwaccel(&ff_##x##_hwaccel); \
}
...
void avcodec_register_all(void)
{
static int initialized;
if (initialized)
return;
initialized = 1;
/* hardware accelerators */
REGISTER_HWACCEL(H263_VAAPI, h263_vaapi);
REGISTER_HWACCEL(H263_VIDEOTOOLBOX, h263_videotoolbox);
...
I don't understand why do these methods even get declared when my config has them set to 0
#define CONFIG_H263_VAAPI_HWACCEL 0
#define CONFIG_H263_VDPAU_HWACCEL 0
#define CONFIG_H263_VIDEOTOOLBOX_HWACCEL 0
...
Btw it builds OK when I use msys/make tooling.

You may be trying to link C code with C++ name mangling.
Try:
extern "C"
{
#include <avcodec.h>
#include <avformat.h>
}

Related

Unresolved external symbols since Visual Studio 2015 update 3: boost python linking error if destructor is virtual

We are getting strange unresolved symbols linking errors since we updated to Visual Studio 2015 update 3. Anyone else encountered the same kind of issues ?
What is really weird is that boost::get_pointer is a template method, defined in a boost header. I do not understand how we can get an undefined external symbol in that case :(.
Here is a reproducer, with boost 1.61 and Python 3.5.1:
#include <vector>
#include <boost/python.hpp>
using namespace boost::python;
class Canard {
public:
Canard() {}
virtual ~Canard() {}
};
BOOST_PYTHON_MODULE(coin)
{
register_ptr_to_python< std::shared_ptr<Canard> >();
}
And the error:
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "class Canard const volatile * __cdecl boost::get_pointer<class Canard const volatile >(class Canard const volatile *)" (??$get_pointer#$$CDVCanard###boost##YAPEDVCanard##PEDV1##Z) referenced in function "private: static struct _typeobject * __cdecl boost::python::objects::make_ptr_instance<class Canard,struct boost::python::objects::pointer_holder<class std::shared_ptr<class Canard>,class Canard> >::get_derived_class_object<class Canard>(struct boost::mpl::bool_<1>,class Canard const volatile *)" (??$get_derived_class_object#VCanard###?$make_ptr_instance#VCanard##U?$pointer_holder#V?$shared_ptr#VCanard###std##VCanard###objects#python#boost###objects#python#boost##CAPEAU_typeobject##U?$bool_#$00#mpl#3#PEDVCanard###Z) CCMasterKernelPyPy C:\work\dev\builds\internal\Master\SDK\MasterKernelPyPy\main.obj 1
But as soon as I remove the virtual in front of the destructor of the Canard class, then it starts working.... Does anyone have a clue ? Is it a Visual Studio bug ?
Visual Studio 2015 update 3 has added lots of features and improvements (see the release notes https://www.visualstudio.com/news/releasenotes/vs2015-update3-vs#visualcpp).
It also have some known issues (https://msdn.microsoft.com/vs-knownissues/vs2015-update3 see the Passing non-pointer-like types to uninitialized_copy section).
To fix your problem you need to explicitly specify the conversion to pointer of your class, explicitly:
namespace boost
{
template <>
Canard const volatile * get_pointer<class Canard const volatile >(
class Canard const volatile *c)
{
return c;
}
}
Good luck,
Ohad

statically link lib file causes link-error

I statically link fw.lib in my C++/CLI project, and get these errors:
Error 1 error LNK2028: unresolved token (0A00001B) "extern "C" unsigned int __cdecl func(unsigned int,unsigned char *)" (?func##$$J0YAIIPAE#Z) referenced in function "public: static void __clrcall Sdk::Native::Method(void)" (?Method#Native#Sdk##$$FSMXXZ) C:\project\Sdk.obj Sdk
Error 2 error LNK2019: unresolved external symbol "extern "C" unsigned int __cdecl func(unsigned int,unsigned char *)" (?func##$$J0YAIIPAE#Z) referenced in function "public: static void __clrcall Sdk::Native::Method(void)" (?Method#Native#Sdk##$$FSMXXZ) C:\project\Sdk.obj Sdk
What do I do wrong ? I did this:
Added the lib path in [project properties -> Library Directories]
Added fw.lib file under [project properties -> Additional Dependencies]
Wrapped all functions in fw.h with extern "C" {...}
Any idea ?
Problem solved...
Apparently when you link, for instance, x64 bit into x32 project (and vice versa ??), the linker produces a very general link-error.
FYI :-)

vs 2010: error LNK2028: unresolved token (0A000342) "extern "C" int __stdcall

The following code is taken from here. I removed all Windows NT part as I am working on Windows 7.
I copied this code and run in visual studio 2010 (New project-> VC++->CLR->CLR Console... ). But it is giving lots of unresolved extern 'c' errors as listed below the code. What wrong I have committed?
#define STRICT 1
#include <windows.h>
#include <iostream>
using namespace std;
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) {
DWORD dwThreadId, dwProcessId;
HINSTANCE hInstance;
char String[255];
HANDLE hProcess;
if (!hWnd)
return TRUE; // Not a window
if (!::IsWindowVisible(hWnd))
return TRUE; // Not visible
if (!SendMessage(hWnd, WM_GETTEXT, sizeof(String), (LPARAM)String))
return TRUE; // No window title
hInstance = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
cout << hWnd << ' ' << dwProcessId << '\t' << String << '\t';
cout << "(None)\n";
CloseHandle(hProcess);
return TRUE;
}
int main(int argc, char *argv[], char *envp[]) {
EnumWindows(EnumWindowsProc, NULL);
return 0;
}
This is giving following Errors(and other similar unresolved extern C errors)
1>wndowfind.obj : error LNK2028: unresolved token (0A000342) "extern "C" int __stdcall
EnumWindows(int (__stdcall*)(struct HWND__ *,long),long)" 3
(?EnumWindows##$$J18YGHP6GHPAUHWND__##J#ZJ#Z) referenced in function "int __cdecl
main(int,char * * const,char * * const)" (?main##$$HYAHHQAPAD0#Z)
1>wndowfind.obj : error LNK2028: unresolved token (0A000346) "extern "C" unsigned long
__stdcall GetWindowThreadProcessId(struct HWND__ *,unsigned long *)"
(?GetWindowThreadProcessId##$$J18YGKPAUHWND__##PAK#Z) referenced in function "int __stdcall
EnumWindowsProc(struct HWND__ *,long)" (?EnumWindowsProc##$$FYGHPAUHWND__##J#Z)
1>wndowfind.obj : error LNK2028: unresolved token (0A000347) "extern "C" long __stdcall
GetWindowLongW(struct HWND__ *,int)" (?GetWindowLongW##$$J18YGJPAUHWND__##H#Z) referenced in
function "int __stdcall EnumWindowsProc(struct HWND__ *,long)"
(?EnumWindowsProc##$$FYGHPAUHWND__##J#Z)
1>wndowfind.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall
EnumWindows(int (__stdcall*)(struct HWND__ *,long),long)"
(?EnumWindows##$$J18YGHP6GHPAUHWND__##J#ZJ#Z) referenced in function "int __cdecl
main(int,char * * const,char * * const)" (?main##$$HYAHHQAPAD0#Z)
1>c:\users\afnan\documents\visual studio 2010\Projects\wndowfind\Debug\wndowfind.exe : fatal
error LNK1120: 10 unresolved externals
1>
1>Build FAILED.
UPDATED
By including the libraries (as suggested in the answers), I was able to run the program successfully. But I am not able to understand why only first character of string is printing not the complete one, as can be seen in the output:
00010060 2652 S (None)
002502B2 5820 C (None)
00090402 5160 w (None)
00050392 5160 w (None)
00060292 3520 F (None)
000C02BA 3520 M (None)
0001021A 3736 E (None)
00040018 896 I (None)
00010170 3580 A (None)
0002003E 2684 D (None)
00030316 4956 N (None)
000202DE 3736 D (None)
0001031E 2652 S (None)
000100EA 2652 P (None)
In the output above, S is actually "start", C is "console" etc I confirmed through spy++ tool.
How can I print the complete string instead of just first character?
CLR projects by default do not include the standard Windows libraries, such as user32.lib.
Edit your project properties, find the Linker Inputs option, and add kernel32.lib user32.lib advapi32.lib which are the usual libraries needed by Win32 code.

Symbols Missing for nsiCookieManager2 program

Please help me with the missing LIBs for this MOZILLA program.
Trying to create cookie using nsICookieManager2
I have tried with all the existing libs in Mozilla SDK
Regards
C:\Code>cl.exe FFCookie.cpp /I "C:\xulrunner-sdk\include" mozalloc.lib xpcomglue.lib /link /LIBPATH:"C:\xulrunner-sdk\lib"
Symbols Missing:
FFCookie.obj : error LNK2019: unresolved external symbol "public: void
__thiscall nsCOMPtr_base::assign_from_gs_contractid_with_er ror(class nsGetServiceByContractIDWithError const &,struct nsID const &)"
(?assign_from_gs_contractid_with_error#nsCOMPtr_base##QA
EXABVnsGetServiceByContractIDWithError##ABUnsID###Z) referenced in
function "public: __thiscall nsCOMPtr::
nsCOMPtr(class
nsGetServiceByContractIDWithError const &)"
(??0?$nsCOMPtr#VnsICookieManager####QAE#ABVnsGe
tServiceByContractIDWithError###Z)
FFCookie.obj : error LNK2019: unresolved external symbol "public: void
__thiscall nsCOMPtr_base::assign_from_qi(class nsQueryInter face,struct nsID const &)"
(?assign_from_qi#nsCOMPtr_base##QAEXVnsQueryInterface##ABUnsID###Z)
referenced in function "public: __t hiscall nsCOMPtr::nsCOMPtr(class
nsQueryInterface)" (??0?$nsCOMPtr#VnsICookieMan
ager2####QAE#VnsQueryInterface###Z) FFCookie.exe : fatal error
LNK1120: 2 unresolved externals
#include "nsICookieManager.h"
#include "nsICookieManager2.h"
#include "nsServiceManagerUtils.h"
#include "nsComPtr.h"
#include "nsNetCID.h"
#include "nsStringAPI.h"
#include "mozilla-config.h"
int main()
{
nsresult rv;
nsCOMPtr<nsICookieManager> cookieManager = do_GetService (NS_COOKIEMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (cookieManager)
{
nsCOMPtr<nsICookieManager2> cookieManager2 = do_QueryInterface(cookieManager);
if (cookieManager2)
{
cookieManager2->Add(NS_LITERAL_CSTRING("ud.abc.com"),
NS_LITERAL_CSTRING("//"),
NS_LITERAL_CSTRING("TK"),
NS_LITERAL_CSTRING("abc"), 0x1, 0x1, 0, -1);
}
}
return 0;
}
Questions:
I dont find any info with function documentation regarding which LIB to include (as I find on MSDN)
Any clue on how to figure out LIB corresponding to particular function for MOZILLA.
The problem isn't with the lib, the symbol missing is defined in the xpcomglue library. However, you seem to have some compile parameters that don't match the parameters used to compile XULRunner/Firefox. The symbols your compiler is looking for contain "QAEX" as parameter description whereas the library defines them with "QAIX". Looking at the name mangling table, your compiler expects unsigned char where Mozilla has unsigned int. I suspect that the reason is you compiling your application without Unicode support - change main() into wmain()?

How do you compile static Taglib libraries for Windows?

I don't want to compile dynamic libs, so this question was not useful.
I downloaded taglib and compiled it using:
cmake -DENABLE_STATIC=ON -DENABLE_STATIC_RUNTIME=ON -DWITH_MP4=ON -G "Visual Studio 10"
That generates the Visual Studio solutions and I can compile the "tag" project which produces tag.lib in taglib/Release.
The problem comes when I try to use the library in a test application - nothing much, just a simple test:
#include "stdafx.h"
#include "fileref.h"
int _tmain(int argc, _TCHAR* argv[])
{
TagLib::FileRef d("");
return 0;
}
I get the following Linker errors:
Error 1 error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall TagLib::FileRef::~FileRef(void)" (__imp_??1FileRef#TagLib##UAE#XZ) C:\...\taglib_test\taglib_test\taglib_test.obj taglib_test
Error 2 error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall TagLib::FileRef::FileRef(class TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)" (__imp_??0FileRef#TagLib##QAE#VFileName#1#_NW4ReadStyle#AudioProperties#1##Z) C:\...\taglib_test\taglib_test\taglib_test.obj taglib_test
Error 4 error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall TagLib::FileName::FileName(char const *)" (__imp_??0FileName#TagLib##QAE#PBD#Z) C:\...\taglib_test\taglib_test\taglib_test.obj taglib_test
Error 3 error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall TagLib::FileName::~FileName(void)" (__imp_??1FileName#TagLib##QAE#XZ) C:\...\taglib_test\taglib_test\taglib_test.obj taglib_test
Error 5 error LNK1120: 4 unresolved externals C:\...\taglib_test\Release\taglib_test.exe taglib_test
Can somebody please give me an idea as to what's going on here?
The following are the preprocessor defines in the tag project:
WIN32
_WINDOWS
NDEBUG
HAVE_CONFIG_H
_CRT_SECURE_NO_DEPRECATE
_CRT_NONSTDC_NO_DEPRECATE
TAGLIB_STATIC
CMAKE_INTDIR="Release"
For those who have had this problem:
I fixed it by defining TAGLIB_STATIC in the test project:
#include "stdafx.h"
//This should have been generated by the build system in taglib_config.h
//but was not.
#define TAGLIB_STATIC
#include "fileref.h"
int _tmain(int argc, _TCHAR* argv[])
{
TagLib::FileRef d("");
return 0;
}

Resources