如题, 使用 VS2017 编译 ooc_test 项目(文章后有 Github 地址), 已经引入 ooc 相关头文件和 ooc.lib 静态链接库, 可能是使用姿势不对或者 VS 没配置好, 报了如下错误
严重性 代码 说明 项目 文件 行 禁止显示状态 错误 LNK2001 无法解析的外部符号 String1Class oc_test E:\projects\demo\ooc_test\vstudio\ooc_test.obj 1
想请教一下正确的使用方法是啥? ps: ooc 的资料比较少, 用的人估计不多。
GtType.h
#ifndef _GT_TYPE_H #define _GT_TYPE_H /************************************************************************/ /* */ /************************************************************************/ #ifdef __cplusplus # define GT_C_START extern "C" { # define GT_C_END } #else # define GT_C_START # define GT_C_END #endif #endif
String1.h 头文件
#ifndef _STRING1_H #define _STRING1_H #include <ooc/ooc.h> #include "GtType.h" GT_C_START DeclareClass(String1, Base); GT_C_END #endif // STRING1_H
impl_String1.h 头文件
#ifndef _IMPL_STRING1_H #define _IMPL_STRING1_H #include "String1.h" #include "GtType.h" GT_C_START ClassMembers(String1, Base) char *name; EndOfClassMembers; Virtuals(String1, Base) EndOfVirtuals; GT_C_END #endif // !_IMPL_STRING1_H
主函数报无法解析外部符号 String1Class
#include "impl_String1.h" #include <exception> typedef struct String1Params { char *cstr; int length; } String1Params; int main() { ooc_init_class(String1); //String1Params p; char s[6] = "hello"; /*p.cstr = s; p.length = 5;*/ //String1 my_string = (String1)ooc_new(String1, (const void *)p); return 0; }
使用 VS2017, github 地址
![]() | 1 wutiantong 2019-02-20 14:41:35 +08:00 这种黑科技看起来真可怕。 |
2 zwh2698 2019-02-22 09:12:39 +08:00 via Android 因为网络的问题,我看不到你 git 上全部代码,但是猜测你应该 string 1 是按照 c++编译的,你的函数声明的地方是 c, 所以就找不到了。 |