对“_imp__InitBizLib”的未定义引用
当尝试在 XP 上使用 eclipse 编写的 C++ 程序使用第 3 方 SDK 时,出现上述错误。根据搜索,我了解到此错误是由链接器未正确指向 .dll 或 .lib 引起的。我已将这些项目的路径包含在环境变量 - PATH 中,也在 Eclipse 中的 Properties\C/C++ Build\Settings\MinGW C++ Linker\Libraries 下。这两项使用的路径是 C:\Program Files\Card Scanning Solutions\SDK
这是控制台输出:
**** Build of configuration Debug for project HelloWorld ****
**** Internal Builder is used for build ****
g++ -IC:\Program Files\Card Scanning Solutions\SDK -O0 -g3 -Wall -c -fmessage-length=0 -lm -v -o src\BizScan.o ..\src\BizScan.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.1/configure --enable-languages=c,c++,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.1 (GCC)
COLLECT_GCC_OPTIONS='-I' 'C:\Program Files\Card Scanning Solutions\SDK' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'src\BizScan.o' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/cc1plus.exe -quiet -v -I C:\Program Files\Card Scanning Solutions\SDK -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.6.1/ -dD ..\src\BizScan.cpp -quiet -dumpbase BizScan.cpp -mtune=i386 -march=i386 -auxbase-strip src\BizScan.o -g3 -O0 -Wall -version -fmessage-length=0 -o C:\DOCUME~1\Game\LOCALS~1\Temp\ccwufpbm.s
GNU C++ (GCC) version 4.6.1 (mingw32)
compiled by GNU C version 4.6.1, GMP version 5.0.1, MPFR version 2.4.1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=65307
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.6.1/../../../../mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include"
ignoring duplicate directory "/mingw/lib/gcc/mingw32/4.6.1/../../../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
C:\Program Files\Card Scanning Solutions\SDK
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++/mingw32
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++/backward
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include-fixed
End of search list.
GNU C++ (GCC) version 4.6.1 (mingw32)
compiled by GNU C version 4.6.1, GMP version 5.0.1, MPFR version 2.4.1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=65307
Compiler executable checksum: 8e56a7b4b7f3db333ff95dd4b2d788a4
COLLECT_GCC_OPTIONS='-I' 'C:\Program Files\Card Scanning Solutions\SDK' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'src\BizScan.o' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/as.exe -o src\BizScan.o C:\DOCUME~1\Game\LOCALS~1\Temp\ccwufpbm.s
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.6.1/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../;/mingw/lib/
COLLECT_GCC_OPTIONS='-I' 'C:\Program Files\Card Scanning Solutions\SDK' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'src\BizScan.o' '-shared-libgcc' '-mtune=i386' '-march=i386'
g++ -LC:\Program Files\Card Scanning Solutions\SDK -lm -o HelloWorld.exe src\HelloWorld.o src\BizScan.o
src\BizScan.o: In function `ZN7BizScan4InitEv':
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:20: undefined reference to `_imp__UseFixedModel'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:22: undefined reference to `_imp__SetTwainScanner'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:23: undefined reference to `_imp__InitScanLib'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:27: undefined reference to `_imp__InitImageLib'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:31: undefined reference to `_imp__InitBizLib'
src\BizScan.o: In function `~BizScan':
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:39: undefined reference to `_imp__UnInitScanLib'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 5648 ms.
这是 BizScan.cpp:
/*
* BizScan.cpp
*
* Created on: Feb 13, 2012
* Author: TFB
*/
#include "BizScan.h"
#include "slibexp.h" // ScanLib SDK header file
#include "..\header_lib\BizExp.h" // ScanLib SDK header file
#include "..\header_lib\ImageExp.h" // ScanLib SDK header file
#include "CSSN.h"
#include "windef.h"
BizScan::BizScan() {
BizScan::Init();
}
const char* BizScan::Init() {
UseFixedModel(11);
const char *scannerSelected = "WIA-A6 Scanner 735";
int result = SetTwainScanner(scannerSelected);
result = InitScanLib(CSSN::GetSDKLicense().c_str());
if(result < 0 && result != -13){
return ScannerErrors(result);
} else {
result = InitImageLib(CSSN::GetSDKLicense().c_str());//initialize Image Lib SDK
if(result < 0 && result != -13)//if error
return ImageErrors(result);//call image lib sdk
result = InitBizLib(CSSN::GetSDKLicense().c_str());//initialize Biz Card Lib Scanner SDK
if(result < 0 && result != -13)//if error
return BizErrors(result);//call biz card scanner Lib SDK error handler
}
return "Successful Initialization !!";
}
BizScan::~BizScan() {
UnInitScanLib();
}
这是 BizScan.h:
/*
* BizScan.h
*
* Created on: Feb 13, 2012
* Author: TFB
*/
#ifndef BIZSCAN_H_
#define BIZSCAN_H_
#include "windef.h"
typedef HINSTANCE hDLL;
class BizScan {
private:
public:
BizScan();
virtual ~BizScan();
const char* Init() ;
};
#endif /* BIZSCAN_H_ */
的相关部分:
/*/////////////////////////////////////////////////////////////////////
//
// SLibExp.h
//
// Card Scanning Solutions (LLC)
// All Rights Reserved
//
/////////////////////////////////////////////////////////////////////*/
#ifndef SLIBEXP_H
#define SLIBEXP_H
#ifdef SDLL
#define SDLL_EXP __declspec( dllexport )
#else
#define SDLL_EXP __declspec( dllimport )
#endif
// Functions Prototypes
#if defined __cplusplus || defined c_plusplus
extern "C"
{
#endif
SDLL_EXP void UseFixedModel(int val);
SDLL_EXP short SetTwainScanner(const char *szStr);
SDLL_EXP short InitScanLib(const char * license);
IMAGE_EXPORT short InitImageLib(const char *licanse);
SDLL_EXP short UnInitScanLib();
#if defined __cplusplus || defined c_plusplus
};
#endif
#endif /* SLIBEXP_H */
这里是slibexp.h 控制台输出中引用的其他两种方法都是在同一文件夹(项目根目录)中的其他头文件中定义的。它们的定义如下:
IMAGE_EXPORT short InitImageLib(const char *licanse);
extern "C" BIZ_EXPORT short InitBizLib(const char *license);
是否有其他地方需要链接这些 .dll。我尝试过使用 LoadLibrary() 方法,但该方法因不属于范围而被拒绝。我应该如何链接到这些 dll?感谢您提供的任何指导。
I am getting the error above when trying to use a 3rd party SDK with a C++ program written using eclipse on XP. Based on searches I understand that this error is caused by the linker not correctly pointing to the .dll or .lib. I have included the path to these items in the Environmental Variable - PATH, and also in eclipse under Properties\C/C++ Build\Settings\MinGW C++ Linker\Libraries. The path used for both of these items is C:\Program Files\Card Scanning Solutions\SDK
Here is the console output:
**** Build of configuration Debug for project HelloWorld ****
**** Internal Builder is used for build ****
g++ -IC:\Program Files\Card Scanning Solutions\SDK -O0 -g3 -Wall -c -fmessage-length=0 -lm -v -o src\BizScan.o ..\src\BizScan.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.1/configure --enable-languages=c,c++,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.1 (GCC)
COLLECT_GCC_OPTIONS='-I' 'C:\Program Files\Card Scanning Solutions\SDK' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'src\BizScan.o' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/cc1plus.exe -quiet -v -I C:\Program Files\Card Scanning Solutions\SDK -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.6.1/ -dD ..\src\BizScan.cpp -quiet -dumpbase BizScan.cpp -mtune=i386 -march=i386 -auxbase-strip src\BizScan.o -g3 -O0 -Wall -version -fmessage-length=0 -o C:\DOCUME~1\Game\LOCALS~1\Temp\ccwufpbm.s
GNU C++ (GCC) version 4.6.1 (mingw32)
compiled by GNU C version 4.6.1, GMP version 5.0.1, MPFR version 2.4.1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=65307
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.6.1/../../../../mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include"
ignoring duplicate directory "/mingw/lib/gcc/mingw32/4.6.1/../../../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/include-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
C:\Program Files\Card Scanning Solutions\SDK
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++/mingw32
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include/c++/backward
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.6.1/include-fixed
End of search list.
GNU C++ (GCC) version 4.6.1 (mingw32)
compiled by GNU C version 4.6.1, GMP version 5.0.1, MPFR version 2.4.1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=65307
Compiler executable checksum: 8e56a7b4b7f3db333ff95dd4b2d788a4
COLLECT_GCC_OPTIONS='-I' 'C:\Program Files\Card Scanning Solutions\SDK' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'src\BizScan.o' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/as.exe -o src\BizScan.o C:\DOCUME~1\Game\LOCALS~1\Temp\ccwufpbm.s
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.6.1/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../;/mingw/lib/
COLLECT_GCC_OPTIONS='-I' 'C:\Program Files\Card Scanning Solutions\SDK' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'src\BizScan.o' '-shared-libgcc' '-mtune=i386' '-march=i386'
g++ -LC:\Program Files\Card Scanning Solutions\SDK -lm -o HelloWorld.exe src\HelloWorld.o src\BizScan.o
src\BizScan.o: In function `ZN7BizScan4InitEv':
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:20: undefined reference to `_imp__UseFixedModel'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:22: undefined reference to `_imp__SetTwainScanner'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:23: undefined reference to `_imp__InitScanLib'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:27: undefined reference to `_imp__InitImageLib'
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:31: undefined reference to `_imp__InitBizLib'
src\BizScan.o: In function `~BizScan':
C:\Documents and Settings\Game\workspace\HelloWorld\Debug/../src/BizScan.cpp:39: undefined reference to `_imp__UnInitScanLib'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 5648 ms.
Here is BizScan.cpp:
/*
* BizScan.cpp
*
* Created on: Feb 13, 2012
* Author: TFB
*/
#include "BizScan.h"
#include "slibexp.h" // ScanLib SDK header file
#include "..\header_lib\BizExp.h" // ScanLib SDK header file
#include "..\header_lib\ImageExp.h" // ScanLib SDK header file
#include "CSSN.h"
#include "windef.h"
BizScan::BizScan() {
BizScan::Init();
}
const char* BizScan::Init() {
UseFixedModel(11);
const char *scannerSelected = "WIA-A6 Scanner 735";
int result = SetTwainScanner(scannerSelected);
result = InitScanLib(CSSN::GetSDKLicense().c_str());
if(result < 0 && result != -13){
return ScannerErrors(result);
} else {
result = InitImageLib(CSSN::GetSDKLicense().c_str());//initialize Image Lib SDK
if(result < 0 && result != -13)//if error
return ImageErrors(result);//call image lib sdk
result = InitBizLib(CSSN::GetSDKLicense().c_str());//initialize Biz Card Lib Scanner SDK
if(result < 0 && result != -13)//if error
return BizErrors(result);//call biz card scanner Lib SDK error handler
}
return "Successful Initialization !!";
}
BizScan::~BizScan() {
UnInitScanLib();
}
Here is BizScan.h:
/*
* BizScan.h
*
* Created on: Feb 13, 2012
* Author: TFB
*/
#ifndef BIZSCAN_H_
#define BIZSCAN_H_
#include "windef.h"
typedef HINSTANCE hDLL;
class BizScan {
private:
public:
BizScan();
virtual ~BizScan();
const char* Init() ;
};
#endif /* BIZSCAN_H_ */
And here is the relevant part of slibexp.h:
/*/////////////////////////////////////////////////////////////////////
//
// SLibExp.h
//
// Card Scanning Solutions (LLC)
// All Rights Reserved
//
/////////////////////////////////////////////////////////////////////*/
#ifndef SLIBEXP_H
#define SLIBEXP_H
#ifdef SDLL
#define SDLL_EXP __declspec( dllexport )
#else
#define SDLL_EXP __declspec( dllimport )
#endif
// Functions Prototypes
#if defined __cplusplus || defined c_plusplus
extern "C"
{
#endif
SDLL_EXP void UseFixedModel(int val);
SDLL_EXP short SetTwainScanner(const char *szStr);
SDLL_EXP short InitScanLib(const char * license);
IMAGE_EXPORT short InitImageLib(const char *licanse);
SDLL_EXP short UnInitScanLib();
#if defined __cplusplus || defined c_plusplus
};
#endif
#endif /* SLIBEXP_H */
The other two methods, referenced in the console output both are defined in other header files that are in the same folder (the project root directory). These are defined as follows:
IMAGE_EXPORT short InitImageLib(const char *licanse);
extern "C" BIZ_EXPORT short InitBizLib(const char *license);
Is there another place I need to link these .dll's. I have tried using the LoadLibrary() method, but that method gets rejected for not being part of the scope. How should I link to these dll's? Thank you for any direction you may offer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看您显示的输出,这是相关的命令:
它包括库的路径,但没有实际库本身的引用。我不知道该库的名称是什么,但假设它是
libBizLib.a
,该命令末尾应该有-lBizLib
;或者,如果您想链接 dll,则可以使用其全名(不带-l
)。(顺便说一下,您提到了该库的 .lib 扩展名。这通常表示 Visual Studio 库。您确定您拥有的版本与 MinGW 兼容吗?)
Looking at the output you show, this is the relevant command:
It includes the path to the library, but there is no reference ro the actual library itself. I don't know what the name of the library is, but let's assume it's
libBizLib.a
, there should be-lBizLib
at the end of that command; or if you want to link against the dll, you can use its full name (without-l
).(By the way, you mention a .lib extension of the library. That usually indicates a Visual Studio library. Are you sure the version you have, is compatible with MinGW?)
我最近也发生了类似的问题。这似乎是因为编译器的差异。该库是使用 MinGW w64 的一个版本构建的,而我的版本足够不同,以至于我无法在该库附带的 .a 文件中进行编译。
但是您可以使用 LoadLibrary 在运行时使用 dll,但是在调用它时必须更加明确。那么 dll 无法加载的主要方式是文件不在 dll 加载路径中或者 dll 的位类型错误(32 位 v 64 位)。
希望有帮助。
A similar issue happened to me recently. It appears to be because of the difference in compilers. Where the library was built with one version of MinGW w64, my version is different enough that I can't compile in the .a file that came with the library.
But you can use dll's at runtime using LoadLibrary, but you then have to be more explicit when calling it. Then the main ways the dll won't load is if the file isn't in the dll load path or if the dll is the wrong bit type (32 bit v 64 bit).
Hope that helps.