How can I use lto with static libraries?
问题 When I try to build static libraries with -flto , I get undefined reference errors: library.cpp : #include <iostream> void foo() { std::cout << "Test!" << std::endl; } main.cpp : void foo(); int main() { foo(); return 0; } Compilation output : $ g++ -flto -c library.cpp $ ar rcs library.a library.o $ g++ -flto main.cpp library.a /tmp/ccZIgxCY.ltrans0.ltrans.o: In function `main': ccZIgxCY.ltrans0.o:(.text+0x5): undefined reference to `foo()' collect2: error: ld returned 1 exit status It works