-
Notifications
You must be signed in to change notification settings - Fork 11
Patching llvm config.cpp to fix a bug
valtron edited this page Dec 23, 2012
·
2 revisions
Once you get LLVM built, you typically use llvm-config with various options to compile a project that uses llvm. For example, g++ -g -O3 toy.cpp `llvm-config --cppflags --ldflags --libs core` -o toy.
--libs prints out LLVM libs. --ldflags prints out some linker flags as well as some system libs (like -lpthread -lm, among others). However, you'll get linker errors if the system libs are specified before the LLVM libs. Simply specifying --ldflags after --libs won't work.
To fix this so you can still use llvm-config, you'll need to patch main in llvm-src/tools/llvm-config/llvm-config.cpp.
- Near the beginning of
main: afterbool PrintLibs = false, PrintLibNames = false, PrintLibFiles = false;, addbool PrintLDFlags = false; - Lower down in the loop that checks the
--options: on the lineOS << "-L" << ActiveLibDir << ' ' << LLVM_SYSTEM_LIBS << ' ' << LLVM_LDFLAGS << '\n';remove<< ' ' << LLVM_SYSTEM_LIBSand addPrintLDFlags = true;on the next line - Near the bottom of
main: beforeOS << '\n';add
if (PrintLDFlags) {
OS << ' ' << LLVM_SYSTEM_LIBS;
}
- Right after
OS << '\n';and before} else if (!Components.empty()) {, add
} else if (PrintLDFlags) {
OS << ' ' << LLVM_SYSTEM_LIBS << '\n';