Visual studio C++ 20 模块导入 .h&.cpp 库
Visual studio C++ 20 module import .h&.cpp lib
lib1 有两个文件
math.h
inline void hello();
和math.cpp
#include <iostream>
#include "math.h"
void hello() {
std::cout << "hello from math";
}
lib2 是一个 c++ 2a 模块库:
export module Bar;
import "math.h";
import std.core;
export namespace bar {
void BarFunc() {
hello();
}
}
visual studio 16.8.0
编译器会说:(Bar.ixx.obj):错误 LNK2001:未解析的外部符号“void __cdecl hello(void)”(?hello@@YAXXZ)
根据目前的信息,我恐怕无法确定问题的原因。所以,我建议你可以使用DUMPBIN来帮助你找到原因。
The /EXPORTS and /SYMBOLS options of the DUMPBIN command-line tool are
useful here. They can help you discover which symbols are defined in
your .dll and object or library files. You can use the symbols list to
verify that the exported decorated names match the decorated names the
linker searches for.
In some cases, the linker can only report the decorated name for a
symbol. You can use the UNDNAME command-line tool to get the
undecorated form of a decorated name.
math.h
inline void hello();
至
void hello();
有效。
lib1 有两个文件
math.h
inline void hello();
和math.cpp
#include <iostream>
#include "math.h"
void hello() {
std::cout << "hello from math";
}
lib2 是一个 c++ 2a 模块库:
export module Bar;
import "math.h";
import std.core;
export namespace bar {
void BarFunc() {
hello();
}
}
visual studio 16.8.0 编译器会说:(Bar.ixx.obj):错误 LNK2001:未解析的外部符号“void __cdecl hello(void)”(?hello@@YAXXZ)
根据目前的信息,我恐怕无法确定问题的原因。所以,我建议你可以使用DUMPBIN来帮助你找到原因。
The /EXPORTS and /SYMBOLS options of the DUMPBIN command-line tool are useful here. They can help you discover which symbols are defined in your .dll and object or library files. You can use the symbols list to verify that the exported decorated names match the decorated names the linker searches for.
In some cases, the linker can only report the decorated name for a symbol. You can use the UNDNAME command-line tool to get the undecorated form of a decorated name.
math.h
inline void hello();
至
void hello();
有效。