V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
waterlaw
V2EX  ›  C

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

  •  1
     
  •   waterlaw · 2019-02-19 16:32:03 +08:00 · 2222 次点击
    这是一个创建于 1864 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题, 使用 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 地址

    2 条回复    2019-02-22 09:12:39 +08:00
    wutiantong
        1
    wutiantong  
       2019-02-20 14:41:35 +08:00
    这种黑科技看起来真可怕。
    zwh2698
        2
    zwh2698  
       2019-02-22 09:12:39 +08:00 via Android
    因为网络的问题,我看不到你 git 上全部代码,但是猜测你应该 string 1 是按照 c++编译的,你的函数声明的地方是 c, 所以就找不到了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   975 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:30 · PVG 04:30 · LAX 13:30 · JFK 16:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.