Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用LNK2005制作C++语言包的C包装器 我有一个跨平台的C项目,现在我想在项目中介绍基于C++的LIB音频,尽可能少地改变。第一次尝试是使用Visual Studio 2013将其集成到Win32中,但以后还需要在iOS和Android上工作_C++_C_Visual Studio_Libphonenumber_Lnk2005 - Fatal编程技术网

用LNK2005制作C++语言包的C包装器 我有一个跨平台的C项目,现在我想在项目中介绍基于C++的LIB音频,尽可能少地改变。第一次尝试是使用Visual Studio 2013将其集成到Win32中,但以后还需要在iOS和Android上工作

用LNK2005制作C++语言包的C包装器 我有一个跨平台的C项目,现在我想在项目中介绍基于C++的LIB音频,尽可能少地改变。第一次尝试是使用Visual Studio 2013将其集成到Win32中,但以后还需要在iOS和Android上工作,c++,c,visual-studio,libphonenumber,lnk2005,C++,C,Visual Studio,Libphonenumber,Lnk2005,所以我创建了这个标题: #ifndef LIB_PN_WRAPPER_H #define LIB_PN_WRAPPER_H #ifdef __cplusplus extern "C" { #endif char* tu_lpn_normalize(char* number); #ifdef __cplusplus } #endif #endif //LIB_PN_WRAPPE

所以我创建了这个标题:

    #ifndef LIB_PN_WRAPPER_H
    #define LIB_PN_WRAPPER_H

      #ifdef __cplusplus
        extern "C" {
      #endif

      char* tu_lpn_normalize(char* number);

      #ifdef __cplusplus
        }
      #endif
    #endif //LIB_PN_WRAPPER
本cpp:

    #include "LibPNWrapper.h"
    #include "phonenumbers/phonenumberutil.h"

    using i18n::phonenumbers::PhoneNumberUtil;

    char* tu_lpn_normalize(char* number) {
      PhoneNumberUtil* util = PhoneNumberUtil::GetInstance();
      return "hello";
    }
但我遇到了这个链接器错误:

错误LNK2005:专用:静态无符号整数常量i18n::PhoneNumber::PhoneNumberUtil::kMinLengthForNsn?kMinLengthForNsn@PhoneNumberUtil@phonenumbers@i18n@@0IB已在LibPNWrapper.obj中定义

这确实在phonenumberutil.h中声明和定义为:

静态常数大小\u t kMinLengthForNsn=2

我理解,通过将其包含在我的cpp中,它将再次声明。然而,我试图:

将它包含在头文件中,但之后我不得不更改文件以编译为C++,而最后仍然存在问题。

在cpp文件中使用命名空间,但没有帮助

我不确定它是因为我混合了C和C++,还是因为我缺少了其他基本的东西。
欢迎所有想法。

kMinLengthForNsn是在标题中定义的全局变量吗?如果是这样的话,你就必须使用关键字extern来正确使用它。kMinLengthForNsn是在libphonenumber的头文件中声明和定义的,这是一个我不想更改的库。所以添加外部不是一个选项。我明白了。我读错了,它很好地封装在libphonenumber的类中。您是否仔细检查了重复动态/静态配置的链接选项?我认为它们在头文件中定义静态变量是不正确的。我把它们移到了源文件,现在就可以了。我在github中发布了一个更改此内容的请求。