1.extern "C" 和dllexport一起使用

库工程GlobalTest的.h代码如下

#ifdef GLOBALTEST_EXPORTS
#      define GT_EXPORT __declspec(dllexport)
#   
else
#      define GT_EXPORT __declspec(dllimport)
#   endif 
    

namespace tt
{
extern "C"  GT_EXPORT void fatalerr(void);
}

 

.cpp

#include "globalMethod.h"

#include 
<iostream>

using namespace tt;
void GT_EXPORT fatalerr(void)
{
    printf(
"fatal error: \n");
    
//exit(0);


application工程的main.cpp 

#pragma comment(lib, "GlobalTest.lib")
#include 
"../GlobalTest/globalMethod.h"

#include 
<iostream>

using namespace tt;
int main()
{
    fatalerr();
    system(
"PAUSE");
    
return 0;


这样是会报连接错误

main.obj : error LNK2019: 无法解析的外部符号 __imp__fatalerr,该符号在函数 _main 中被引用 

 

如果不使用namespace就不会。不解。 

 

2.const type& fun() const和type& fun(),用的甚好,无甚笔记。(使用时需留意const 指针)

相关文章:

  • 2021-10-21
  • 2022-12-23
  • 2022-02-14
  • 2021-06-15
  • 2022-12-23
  • 2021-12-28
  • 2021-09-15
  • 2021-09-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2021-08-29
  • 2021-05-20
  • 2021-10-24
相关资源
相似解决方案