So erzwingen Sie, dass gcc eine nicht verwendete statische Bibliothek verknüpft
Ich habe ein Programm und eine statische Bibliothek:
// main.cpp
int main() {}
// mylib.cpp
#include <iostream>
struct S {
S() { std::cout << "Hello World\n";}
};
S s;
Ich möchte die statische Bibliothek verlinken (libmylib.a
) zum Programmobjekt (main.o
), obwohl letzterer kein Symbol des ersteren direkt verwendet.
Die folgenden Befehle scheinen nicht zum Job zu gehöreng++ 4.7
. Sie werden offenbar ohne Fehler oder Warnungen ausgeführtlibmylib.a
wird nicht verlinkt:
g++ -o program main.o -Wl,--no-as-needed /path/to/libmylib.a
oder
g++ -o program main.o -L/path/to/ -Wl,--no-as-needed -lmylib
Hast du bessere Ideen?