I am getting this error while using the command "llvmc -O3 -Wall hello.cpp" where hello.cpp is some cpp file on my machine. llvmc is the driver calling a bunch of tools like llvm-g++, opt, llc etc. I think the llvmc tool could not probably locate the llvm-g++ tool. I would like to know where should I specify the path to llvm-g++ for llvmc to find them. Also can someone give me the link to some tutorial on llvmc because i couldn't find it on llvm.org webpage. My llvmc is in /llvm/tools/llvmc. While llvm-g++ is inside /llvm/Debug/bin/.
thanks.
IIRC, llvmc just use your PATH environment variable, so you should set it to /path/to/llvm/Debug/bin:$PATH
Also take a look at llvmc --help output, there should be a flag to set path to llvm-g++.
Be aware that llvmc have been removed in LLVM 3.0.
If you are not restricted to gcc frontend, try to compile with clang . clang uses llvm as backend as well (so you can --emit-llvm if you like).
If you cannot use clang, you might want to use DragonEgg at llvm
Related
I've been using a .bat file to build my applications for years. Recently, switched to CMake for it's elegancy and I ran into a situation where I had to guess the flags that I should put into CMake's add_link_options and add_compile_options
Example flags that I've used in my BAT file,
-s WASM=1 --bind -s MODULARIZE=1
And, In CMake this flags have become (After trial and error),
add_compile_options("SHELL: -s WASM=1")
add_link_options("SHELL: --bind")
add_link_options("SHELL: -s MODULARIZE=1")
Honestly, I can't find any information regards flags that add_link_options and add_compile_options supports.
I know what is a linker is but lost when it comes to add_link_options or linker flags.
I'm used to compile everything in single line and now in CMake everything appear to be involve separate steps.
I am not sure what your problem is, but here is a full working sample from a Wasm project that sets project-wide strict mode and disabling of exception support:
if (EMSCRIPTEN)
add_compile_options(-fno-exceptions "SHELL:-s STRICT=1")
add_link_options("SHELL:-s STRICT=1")
endif()
Note in particular that, as it has a [compile+link] marker in the emscripten settings, -s STRICT=1 has to be used both for compiling and for linking, thus it appears in each.
The if(EMSCRIPTEN) around is there because this project can also be built for Windows and Linux.
The options you can pass to the compiler or linker depends on which compiler or linker you use. For example if you fork GCC and add a -Wstackoverflow-copy-pasta option, you can pass that option to add_compile_options(), but other people using standard GCC cannot.
So the answer to your question seems to be, read your compiler and linker documentation.
I'm using some features in my C++ programs that I need -std=c++11 option set in g++
Is it possible set this option as a default and don't be necessary use this all time I compile it?
Or how to set this in Makefile.
Yes, you typically set this in a Makefile:
CXXFLAGS=-std=c++11
One layer above you can also detect a suitable compiler via autoconf, cmake or whichever other meta-buildtool you might deploy.
You of course play games as define g++11 as g++ -std=c++11 but such set-ups are not portable.
g++-6.* will default to c++14 so at some this switch will be implicit. But it might take a really long time for all those RHEL and CentOS boxen with g++-4.4.* to disappear. Those may not even handle your current project...
Yes, upgrade to GCC 6.1:
The C++ frontend now defaults to C++14 standard instead of C++98
From https://gcc.gnu.org/ml/gcc/2016-04/msg00244.html
You can have a makefile do this as follows (this is a simple version with no variables).
out: source.cpp
g++ -std=c++11 source.cpp -o out
Use your build system of choice. Be that make, SCons, CMake, qmake or something else, and set the required option. Should take all of 30 seconds and you're done.
Or, upgrade your compiler to a version that uses C++11 by default.
I have a code on my computer uses Petsc which depends on mpi. On my computer it works well. I put it on cluster, exported paths of gcc, Petsc and openmpi (although I was using mpich on my computer I hope openmpi will also work) to LD_LIBRARY_PATH and PATH. I also changed paths in makefile. Petsc, gcc, openmpi were all available on cluster so I did not configure anything. When I did make, compiler gave error:
fatal error: mpi.h: No such file or directory
I know I did not give complete information but I can tell more if needed. How can I make the Petsc to know where is mpi.h?
Typically, you should use mpicc (or mpicxx for C++) to compile instead of gcc (or g++ for C++). These commands are simple wrappers around gcc and g++ that simply add in the appropriate -I/path/to/mpi/includes and -L/path/to/mpi/libs automatically and should be included with your openmpi install. In the absence of that, simply add -I/path/to/mpi/includes in your command to compile the appropriate files. This tells the compiler where to look for the appropriate header files.
To answer the question. To prevent a C/C++ editor from showing errors as you tyoe in the "special code" just use:
#include </usr/include/mpi/mpi.h>
which seems to be a link -- but doing that turns off the errors in Netbeans editor so I can code without distraction.
Note: Using Ubuntu 18.04 Desktop as editing machine -- and testing run machine -- but I compile manually using mpic as noted previously.
sudo mpicc c_pi.c -o c_pi
and then...
mpiexec ./c_pi
hth
I would like to compile software using the autotools build system to LLVM bitcode; that is, I would like the executables obtained at the end to be LLVM bitcode, not actual machine code.
(The goal is to be able to run LLVM bitcode analysis tools on the whole program.)
I've tried specifying CC="clang -emit-llvm -use-gold-plugins" and variants to the configure script, to no avail. There is always something going wrong (e.g. the package builds .a static libraries, which are refused by the linker).
It seems to me that the correct way to do it would be that LLVM bitcode should be a cross-compilation target. to be set with --host=, but there is no such standard target (even though there is a target for Knuth's MMIX).
So far I've used kludges, such as compiling with CC="clang -emit-llvm -use-gold-plugins" and running linking lines (using llvm-ld or llvm-link) manually. This works for simple packages such as grep.
I would like a method that's robust and works with most, if not all, configure scripts, including when there are intermediate .a files, or intermediate targets.
There are some methods like this. But for simple builds where intermediate static libraries are not used, then you can do something simpler. The list of things you will need are
llvm, configured with gold plugin support. Refer to this
clang
dragonegg, if you need front-end for fortran, go, etc.
The key is to enable '-flto' for either clang or dragonegg(front-end), both at compile time and link time. It is straightforward for clang:
CC = clang
CLINKER = clang
CFLAGS = -flto -c
CLINKFLAGS = -flto -Wl,-plugin-opt=also-emit-llvm
If needed, add additional '-plugin-opt' option to specify llvm-specific codegen option:
-Wl,-plugin-opt=also-emit-llvm,-plugin-opt=-disable-fp-elim
The dumped whole problem bytecode would be sitting along with your final executable.
Two additional things are needed when using dragonegg.
First, the dragonegg is not aware of the location of llvm gold plugin, it needs to be specified in the linker flags like this -Wl,-plugin=/path/to/LLVMgold.so,-plugin-opt=...
Second, dragonegg is only able to dump IR rather than bytecode. You need a wrapper script for that purpose. I created one here. Works fine for me.
I'd like to change my default compiler from llvm-g++ to g++ on osx, whats the cleanest/simplest way to do this?
There is no “default” compiler as such. The operating system is compiler unaware. Tools will choose different compilers depending on different factors. Xcode for instance can be configured to use a different default compiler.
If, on the other hand, you want to configure your terminal to use a different default compiler, simply adjust the $PATH variable so that your GCC installation is found before your LLVM installation. In the simplest case, this can be done by adding the following line to your $HOME/.bashrc file (assuming you are using bash as the shell):
export PATH=path/to/gcc/:$PATH
(After that you need to reload your shell before the changes take effect.)