我正在关注https://cygwin.com/cygwin-ug-net/dll.html中的“构建和使用 DLL”教程。我制作了 mydll.cpp 文件:
#include <iostream>
void hello()
{
std::cout << "Hello World of DLL" << std::endl;
}
编译并链接它:
g++ -c mydll.cpp
g++ -shared -o mydll.dll mydll.o
然后尝试在 main.cpp 中使用 hello() 函数:
int main ()
{
hello ();
}
链接后g++ -o main main.cpp -L./ -l mydll
得到:
error: 'hello' was not declared in this scope
hello();
该教程指出一切都应该正常工作。我错过了什么?