GCC是否有办法在链接包含具有相同名称的类的库时生成警告?例如
Port.h
class Port {
public:
std::string me();
};
Run Code Online (Sandbox Code Playgroud)
Port.cpp
#include "Port.h"
std::string Port::me() { return "Port"; }
Run Code Online (Sandbox Code Playgroud)
FakePort.h
class Port {
public:
std::string me();
};
Run Code Online (Sandbox Code Playgroud)
FakePort.cpp
#include "FakePort.h"
std::string Port::me() { return "FakePort"; }
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include "Port.h"
int main() {
Port port;
std::cout << "Hello world from " << port.me() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
建造
# g++ -c -o Port.o Port.cpp
# ar rc Port.a Port.o
# g++ -c -o FakePort.o FakePort.cpp
# ar rc FakePort.a FakePort.o
# …
Run Code Online (Sandbox Code Playgroud)