我正尝试在C++中创建并链接一个静态库。我有两个文件:
helloWorld.cppG ++/C++无法链接库
#include <iostream>
int main(int argc, char const *argv[]) {
std::cout << "I'm inside main." << '\n';
printHello();
return 0;
}
libraryHello.cpp
#include <iostream>
void printHello() {
std::cout << "Hello" << '\n';
}
我运行这些命令(基于http://www.techytalk.info/c-cplusplus-library-programming-on-linux-part-one-static-libraries/):
前两位顺利,当试图编译主文件时出现这样的错误:
helloWorld.cpp: In function ‘int main(int, const char**)’:
helloWorld.cpp:5:14: error: ‘printHello’ was not declared in this scope
它看起来好像根本没有加载它并且找不到printHello。编译,链接或其他任何事情时,我有什么错误吗?我想要做的就是使用静态库从main调用printHello()过程并将其链接到helloWorld.cpp。
我的编译器:G ++ 5.4.0,操作系统:Ubuntu的16.04 32位