Link errors when linking LLVM - c++

So I'm following the LLVM Kaleidoscope tutorial (I have LLVM 3.4 on a Ubuntu 14.04 box) and I get a LOT of link errors like:
/test.cpp:542: undefined reference to `llvm::getGlobalContext()'
test.cpp:556: undefined reference to `llvm::Module::Module(llvm::StringRef, llvm::LLVMContext&)'
Even If I explicitly copy and paste the code listing from the website into a seperate file, I still get the errors.
I compile by doing
clang++ -g -O3 test.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core`

So I've done this:
dzur:~> cp ~/sources/llvm/examples/Kaleidoscope/Chapter3/toy.cpp .
dzur:~> clang++ -g toy.cpp `~/builds/build-llvm/Debug+Asserts/bin/llvm-config --cxxflags --ldflags --system-libs --libs core`
and it's working fine on my (also ubuntu) system. The llvm-config referenced there is my build of top of tree llvm. I haven't tried with one of the previous releases as I don't have them handy, but hopefully this helps.

I figured out that if I remove the --system-libs flag it will compile without issue. I know this will probably bring out other bugs but it solves this problem.

Related

WxWidgets with Mingw wx/msw/libraries.h: not found

I'm using Debian 11, I installed Mingw and built WxWidgets with the following command:
../configure --prefix=/usr/x86_64-w64-mingw32 --host=x86_64-w64-ming32 --build=x86_64-linux --with-msw && make && sudo make install
And I'm using the following command to build:
x86_64-w64-mingw32-g++ wx.cpp `wx-config --cxxflags --libs std,aui`
I receive the following error:
wx/msw/libraries.h: not found
But file exists at: /usr/x86_64-w64-mingw32/include/wx-3.2/wx/msw/libraries.h
Where am I going wrong?
PS: I don't use any kind of IDE.
Friends, it finally worked, that's what you said above, the wx-config that is linked to the terminal, is only for linux, what was with the compilation for Windows inside /usr/x86_64-w64-mingw32/bin /wx-config.
When I want to compile for linux I pass:
g++ wx.cpp `wx-config --cxxflags --libs std,aui`
When I go to Windows I pass:
x86_64-w64-mingw32-g++ wx.cpp `/usr/x86_64-w64-mingw32/bin/wx-config --cxxflags --libs std,aui`
PS: I had to copy some dlls to the application folder, but it all worked out.
Thank you very much for everyone's patience.

Kaleidoscope tutorial cannot find header `ExecutorProcessControl.h`

To follow Kaleidoscope tutorial part 4, I downloaded the header file KaleidoscopeJIT.h. But once I include it, I get the following error
$ clang++ -g main.cpp kaleidoscope.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core orcjit native` -O3 -o kaleidoscope
In file included from kaleidoscope.cpp:18:
././include/KaleidoscopeJIT.h:21:10: fatal error: 'llvm/ExecutionEngine/Orc/ExecutorProcessControl.h' file not found
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
The closest information to it I could find at documentation page, but there is no information on how to successfully compile it. Any suggestions on how to resolve header dependency?
Here are my config options,
$ llvm-config --cxxflags --ldflags --system-libs --libs core orcjit native
-I/usr/lib/llvm-10/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-L/usr/lib/llvm-10/lib
-lLLVM-10
Make sure you pull the correct files. You are using llvm-10 so you need to use the kaleidoscope tutorial from that version.

Trouble compiling code from LLVM Kaleidoscope tutorial

When I used g++ -std=c++17 toy.cpp -o toy to compile the toy.cpp file without the header #include "llvm/ADT/STLExtras.h" in the toy.cpp file, everything was fine and I produced a "working" binary file.
However, when I added the #include "llvm/ADT/STLExtras.h" line to the toy.cpp file and compile it with the command g++ -std=c++17 toy.cpp -o toy, the terminal crushed me with the following output:
-bash: llvm-config: command not found
toy.cpp:1:10: fatal error: 'llvm/ADT/STLExtras.h' file not found
#include "llvm/ADT/STLExtras.h"
The same thing still happens even if I used
"clang++ -g -O3 toy.cpp llvm-config --cxxflags --ldflags --system-libs --libs core -o toy"
instead of "clang++ -g -O3 toy.cpp llvm-config --cxxflag" in the tutorial. My guess is that there's something wrong with the llvm-config thing. It's been bothering me for a while, please teach me how to solve it.
Link to the toy.cpp code
The answer to this is "llvm-config" is not working as expected.
Just check with which llvm-config to figure out whether you got this program. (mine is /usr/local/opt/llvm#8/bin/llvm-config). Or you can install with brew install llvm.
By the way, I came up with the same issue lately on kaleidoscope tutorial (ch2), but I want to know why the #include "llvm/ADT/STLExtras.h fails after several attempts on $(llvm-config --cxxflags --ldflags), etc or we aren't able to compile following chapter's code simply by removing the header declaration when llvm include files are necessary.

llvm module can not be found

I tried to follow the instructions in http://releases.llvm.org/2.6/docs/tutorial/JITTutorial1.html to have make my own function and produce llvm IR. However, executing
c++ -g tut1.cpp llvm-config --cxxflags --ldflags --libs core -o tut1, I am stopped by:
"llvm/Module.h": No such file or Directory.
Does anyone know how can I solve this problem?
2.6 is very old. Try newer LLVM and tutorial, like this one.

C++ Allegro5 CodeBlocks Linker

I'm running Ubuntu. I followed each and every step in the http://wiki.allegro.cc for installation and set up of Allegro5. If I run my program from the command line, I know I need to use
gcc -Wall main.cpp `pkg-config --cflags --libs allegro-5.0
plus any other packges I use. (I don't know what all of it means, but I know I need it)
What I need help with if figuring out what I need to do in Codeblocks > Settings > Compiler so that it will link to the allegro library so that I don't get a hundred and one undefined reference errors. I don't know what I'm looking for, and I don't know where to look. Help a new guy out.
Thanks.
edit: I know I'd need
allegro-config --libs --static
in the Linker for Allegro 4.2
Where can I look and what do I need for Allegro5?
If Codeblocks doesn't support entering `pkg-config --cflags --libs allegro-5.0` directly, then just open up a terminal and type in (no backticks):
pkg-config --cflags --libs allegro-5.0
Then copy/paste the result of that into the compiler settings inside Codeblocks.