问题
I am trying to use the ADTF streaming library in my project. When I am including the lib, I get the LNK1181 error. The library comes with the headers, the lib files and dll files.
I have added the path inside the C/C++ -> General -> Additional Include Directories.
In addition, I have added the library inside the Linker -> Input -> Additional Dependencies.
Here is also the error screenshot.
Update: I have changed the location of the dll and the libs to my project path and include it again. It does not complain now about the lib itself. Now I am getting an error LNK2001. I believe it is also a linker error.
And here where it all goes wrong!
Update 2: After I see the full log of the build. This appears, I think this means, the linker can't find my lib. Is that right?
The main application code is as this:
#include "pch.h"
#include <iostream>
#include "adtf_streaming.h"
using namespace adtfstreaming;
int main()
{
std::cout << "Hello World!\n";
IADTFFileReader *pFileReader = IADTFFileReader::Create();
}
and the header file which is trying to read/ import my lib is
#ifndef _ADTF_STREAMING_LIBRARY_DLL_
#define _ADTF_STREAMING_LIBRARY_DLL_
#ifdef WIN32
#ifdef STREAMINGLIB_EXPORTS
#pragma message ("Create ADTF Streaming Library ")
// export symbols
#define DOEXPORT __declspec( dllexport )
#else
#pragma message ("Use dynamic ADTF Streaming Library ")
#ifdef _DEBUG
#pragma comment( lib, "adtfstreamingD_290.lib" )
#else
#pragma comment( lib, "adtfstreaming_290.lib" )
#endif
#define DOEXPORT __declspec( dllimport )
#endif
#else
#ifdef STREAMINGLIB_EXPORTS
#define DOEXPORT __attribute__ ((visibility("default")))
#else
#pragma comment( lib, "adtfstreaming_290.lib" )
#define DOEXPORT __declspec( dllimport )
#endif
#endif
//standard includes
#include <stdlib.h>
#include <string.h>
//adtf base types and errors
#include "adtf_base_ref.h"
//streaming lib version
#include "adtf_streaming_version.h"
//adtf streaming lib package headers
#include "adtf_streaming_pkg.h"
#endif //_ADTF_STREAMING_LIBRARY_DLL_
回答1:
You need to specify the Additional Library Directories, in Linker properties, to set the directory where you have the lib file. You don't need to include the libs in Additional Dependencies because you are doing it in the lib header file #pragma comment( lib, "adtfstreamingD_290.lib" )
when you compile your app in debug or #pragma comment( lib, "adtfstreaming_290.lib" )
when you compile in release. But you need to specify where are these libs in Additional Library Directories.
If you see the lib include file, you see that if STREAMINGLIB_EXPORTS macro is defined all functions with DOEXPORT modifier are exported functions #define DOEXPORT __declspec( dllexport )
. But if this macro is not defined #define DOEXPORT __declspec( dllimport )
, the same functions are imported functions. It is because the dll needs to specify that this functions are exported functions, so in the dll code someone has defined this macro. Because in your code you have not (and you must not do) define this macro, this functions are imported functions.
回答2:
ADTF Streaming Library requires VS 2010 and is not compatible with other versions! So make sure to use it with v100 build tools. Or change to ADTF File Library a.k.a. IFHD, which is the v141 compatible successor and works with ADTF 2.x and ADTF 3.x as well. Note that the Lib comes completely open source licensed. See ADTF .dat trace file reader for some overview
回答3:
I found the answer to the problem. Well, a combination of problems.
The library was built to support 0x86 machines only. I have built it again to support 0x64 and it worked.
P.S. It worked on Visual Studio 2017 too, unfortunately the documentation is poor and lacks information.
来源:https://stackoverflow.com/questions/58605032/linking-a-library-fails-with-link1181-on-vs17