C 语言封装的面向对象库 ooc 提示符号解析错误

2019-02-19 16:32:03 +08:00
 waterlaw

如题, 使用 VS2017 编译 ooc_test 项目(文章后有 Github 地址), 已经引入 ooc 相关头文件和 ooc.lib 静态链接库, 可能是使用姿势不对或者 VS 没配置好, 报了如下错误

严重性	代码	说明	项目	文件	行	禁止显示状态
错误	LNK2001	无法解析的外部符号 String1Class	ooc_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 地址

2255 次点击
所在节点    C
2 条回复
wutiantong
2019-02-20 14:41:35 +08:00
这种黑科技看起来真可怕。
zwh2698
2019-02-22 09:12:39 +08:00
因为网络的问题,我看不到你 git 上全部代码,但是猜测你应该 string 1 是按照 c++编译的,你的函数声明的地方是 c, 所以就找不到了。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/536605

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX