解决方案:感谢所有对此问题发表评论的人,但是我在另一个论坛上解决了该问题,并认为我将在此处发布有相同问题的任何人的答案。
因此,我猜只有动态库会使用__declspec(dllexport),因此当您尝试创建静态库时,方法会被导出(名称需要修改为与c ++兼容),因此在声明extern“ C”时__declspec ....最终会导致尝试静态链接时无法识别的方法名称。
因此,简单修复.....删除__declspec
我有2个项目,一个是静态库,另一个只是win32应用程序。
我只想将我创建的库包含到我的win32应用程序中,但是g ++一直给我这个错误:
../MyLib/TestClass.h:16:对` imp __ZTV9TestClass'的未定义引用
那是我尝试编译应用程序时遇到的错误,即使该文件是库的一部分。
我试图创建此项目的最简化版本,以尝试找到错误。
这是两个项目的源文件:
MyLib.h-这是客户端用于引用库中函数的主要包含文件
#ifndef MYLIB_H
#define MYLIB_H
#include "libexport.h"
#include "TestClass.h"
#endif /* MYLIB_H */
Run Code Online (Sandbox Code Playgroud)
libexport.h-用于定义导入/导出关键字的通用文件
#ifndef LIBEXPORT_H
#define LIBEXPORT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef LIB
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
}
#endif
#endif /* LIBEXPORT_H */
Run Code Online (Sandbox Code Playgroud)
测试类
#ifndef TESTCLASS_H
#define TESTCLASS_H
#include "libexport.h"
class DLL_EXPORT TestClass
{
public:
TestClass() {};
virtual ~TestClass() {};
void TestFunc();
};
#endif /* TESTCLASS_H …Run Code Online (Sandbox Code Playgroud) 我已经做了10年的c ++程序员,我习惯于创建库,然后从我现有的项目链接到它们.但是在java中,我有2个项目,一个是我的游戏引擎,另一个是我想要使用的测试环境,下面是它的结构:
com.logic.engine
com.logic.testapp
Run Code Online (Sandbox Code Playgroud)
但在我的测试应用程序中,我无法做到
import com.logic.engine.*;
Run Code Online (Sandbox Code Playgroud)
它根本找不到参考.
如何在不必将我的引擎复制并粘贴到我用它编写的每个程序中的情况下执行此操作?