Building llvm examples - llvm

I followed the below from http://llvm.org/docs/GettingStarted.html - which completed successfully:
cd where-you-want-llvm-to-live
get the code
...
make
I put these in my home directory, so my structure looks like
~/llvmHome/llvm/<souce code is here>
~/llvmHome/build/Debug+Asserts/bin/<clang++ executables etc are here>
I'm attempting to follow the steps on http://llvm.org/docs/tutorial/LangImpl3.html to build the example.
I'm performing
cd ~/llvmHom/llvm/examples/Kaleidoscope/Chapter3 //so I'm where I checked out the source code
Then, I'm trying:
~/llvmHome/build/Debug+Asserts/bin/clang++ -g -O3 toy.cpp `~/llvmHome/build/Debug+Asserts/bin/llvm-config --cppflags --ldflags --libs core` -o toy
This gives warnings, and up to the first error
In file included from toy.cpp:1:
In file included from ~/llvmHome/llvm/include/llvm/IR/Verifier.h:24:
In file included from ~/llvmHome/llvm/include/llvm/ADT/StringRef.h:14:
~/llvmHome/llvm/include/llvm/Support/Allocator.h:82:42: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
virtual MemSlab *Allocate(size_t Size) override;
^
~/llvmHome/llvm/include/llvm/Support/Allocator.h:83:42: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
virtual void Deallocate(MemSlab *Slab) override;
^
In file included from toy.cpp:2:
In file included from ~/llvmHome/llvm/include/llvm/IR/DerivedTypes.h:21:
In file included from ~/llvmHome/llvm/include/llvm/IR/Type.h:19:
In file included from ~/llvmHome/llvm/include/llvm/ADT/APFloat.h:20:
In file included from ~/llvmHome/llvm/include/llvm/ADT/APInt.h:19:
In file included from ~/llvmHome/llvm/include/llvm/ADT/ArrayRef.h:14:
~/llvmHome/llvm/include/llvm/ADT/SmallVector.h:235:20: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
void push_back(T &&Elt) {
^
~/llvmHome/llvm/include/llvm/ADT/SmallVector.h:187:15: error: no member named 'move' in namespace 'std'; did you mean simply 'move'?
*Dest = ::std::move(*I);
^~~~~~~~~~~
move
Some examaples suggest using g++ to compile, trying that gives
g++ -g -O3 toy.cpp `~/llvmHome/build/Debug+Asserts/bin/llvm-config --cppflags --ldflags --libs core` -o toy
In file included from ~/llvmHome/llvm/include/llvm/ADT/StringRef.h:14:0,
from ~/llvmHome/llvm/include/llvm/IR/Verifier.h:24,
from toy.cpp:1:
~/llvmHome/llvm/include/llvm/Support/Allocator.h:82:40: warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]
~/llvmHome/llvm/include/llvm/Support/Allocator.h:83:40: warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11 [enabled by default]
In file included from ~/llvmHome/llvm/include/llvm/ADT/ArrayRef.h:14:0,
from ~/llvmHome/llvm/include/llvm/ADT/APInt.h:19,
from ~/llvmHome/llvm/include/llvm/ADT/APFloat.h:20,
from ~/llvmHome/llvm/include/llvm/IR/Type.h:19,
from ~/llvmHome/llvm/include/llvm/IR/DerivedTypes.h:21,
from toy.cpp:2:
~/llvmHome/llvm/include/llvm/ADT/SmallVector.h:235:20: error: expected ‘,’ or ‘...’ before ‘&&’ token
I'm not sure how how to debug this further, any ideas on what I'm getting incorrect?
Should I be linking to libraries under ~/llvmHome/build/ instead of into the source code?

LLVM (and clang) recently switched to C++ 11. So, you need to have reasonable compiler (e.g. clang or gcc 4.7+) and compile everything with -std=c++11 flag.

Related

how can I use CERN Root with C++17?

Apparently, CERN's "Root" software is compatible (as of version 6.12) with C++17. However, I have been completely unable to get this to work with the newest version (6.20) and all previous questions I found on this topic are from a few years ago.
Does anyone with Root experience know if there is a particular compiler option to get it to work with C++17?
Examples of errors I get when trying to compile a trivial "Hello world" program:
The following is (I think) due to the "TFile.h" header implicitly loading "TString.h":
/usr/local/bin/root_v6.20.02/include/ROOT/RStringView.hxx:32:84: error: conflicting declaration of template ‘template<class _CharT, class _Traits> using basic_string_view = std::experimental::__ROOT::basic_string_view<_CharT, _Traits>
An example of another (more mysterious, to me at least) error is:
/usr/include/c++/7/ext/concurrence.h:53:16: error: ‘_Lock_policy’ does not name a type
static const _Lock_policy __default_lock_policy =
^~~~~~~~~~~~
In file included from /usr/include/c++/7/iostream:38:0,
from test.cpp:1:
/usr/include/c++/7/ext/concurrence.h: In function ‘void std::__throw_concurrence_lock_error()’:
/usr/include/c++/7/ext/concurrence.h:102:5: error: ‘__concurrence_lock_error’ was not declared in this scope
{ _GLIBCXX_THROW_OR_ABORT(__concurrence_lock_error()); }
^
/usr/include/c++/7/ext/concurrence.h:102:5: note: suggested alternative:
In file included from /usr/include/c++/7/memory:74:0,
from /usr/local/bin/root_v6.20.02/include/ROOT/TypeTraits.hxx:15,
from /usr/local/bin/root_v6.20.02/include/TString.h:29,
from /usr/local/bin/root_v6.20.02/include/TNamed.h:26,
from /usr/local/bin/root_v6.20.02/include/TKey.h:15,
from /usr/local/bin/root_v6.20.02/include/TBasket.h:28,
from /usr/local/bin/root_v6.20.02/include/ROOT/TIOFeatures.hxx:14,
from /usr/local/bin/root_v6.20.02/include/TTree.h:30,
from /usr/local/bin/root_v6.20.02/include/TNtuple.h:24,
from test.cpp:2:
/usr/include/c++/7/ext/concurrence.h:67:9: note: ‘__gnu_cxx::__concurrence_lock_error’
class __concurrence_lock_error : public std::exception
I am using the latest version of g++ and Root, on Linux, and have the following options in my Makefile:
CXX = g++
CXXFLAGS = -march=native `root-config --cflags --libs` -std=c++17
LDFLAGS = `root-config --cflags --libs`
Any comments about a possible workaround would be appreciated, or perhaps there is some additional option I need to add in the Makefile? It would also be helpful to know if it is advisable to stick to C++11/14 when using Root libraries.
You can use root only with the c++ standard with which your root version has been compiled. This is a known inconvenience and I believe the developers would be happy if/when they get this sorted out. The build configuration root-config --cflags should set the appropriate c++ standard. This might very well be c++17 (it is for me)
pseyfert#robusta:~ > root-config --cflags
-pthread -std=c++17 -m64 -fdiagnostics-color -march=native -Wextra -Wall -Wshadow -I/home/pseyfert/coding/root-install/include
If you compile root from source, then CMAKE_CXX_STANDARD=17 or cxx17=ON (doc) are the build options you want to set to compile root with c++17 and use c++17 in all downstream projects.
If you use a binary installation of root that switch needs to be done by whoever provides the build.

Issue after GCC upgrade C++

Current Code Base
Os-Linux x64, have perl code, boost 1.42, GCC 4.4.7 and other dependencies as a part of project code.
The build works fine.
After Upgrade of GCC to 4.9.2
We made a copy of existing Linux ec2 instance (which works fine) and upgraded its GCC to 4.9.2.
When we are trying to build the project, getting the below error.
webql/rt/bootstrap: Compiling main.cxx
webql/rt/bootstrap: #/archive/webql/build/al/current/base/dev/general/gfilt -pthread -fPIC -DU_HAVE_NAMESPACE=1 -D_FILE_OFFSET_BITS=64 -D_unix -D_BSD -fexceptions -fmessage-length=0 -I/home/builder/archive/webql/build/al/current/base/dev/perl/core -DQL2_PLATFORM="al" -DJAVA_ARCH="amd64" -fvisibility=hidden -D_XOPEN_SOURCE=500 -I/archive/webql/build/al/current/base/dev/general -I/archive/webql/build/al/current/base/dev/general/include -I. -I/archive/webql/build/al/current/base/dev -I/archive/webql/build/al/current/base/dev/xml -I/archive/webql/build/al/current/base/dev/xml/libxml -I/archive/webql/build/al/current/base/dev/xml/libxslt -I/archive/webql/build/al/current/base/packages/al/inst/include -I/archive/webql/build/al/current/base/dev/zlib -I/archive/webql/build/al/current/base/packages/al/inst/jdk/include -I/archive/webql/build/al/current/base/packages/al/inst/jdk/include/linux -I/usr/java/include -I/usr/java/include/linux -I/mnt/usr/include -ggdb3 -O3 -DNDEBUG -c -o /archive/webql/build/al/current/base/dist/alr/obj/webql/rt/bootstrap/main.o main.cxx
In file included from ../perlapi/perl.h::,
from ../perlapi/Utils.h:,
from main.cxx::
/archive/webql/build/al/current/base/dev/perl/core/perl.h::49: error: declaration of int setresuid(uid_t, uid_t, uid_t) has a different exception specifier
int setresuid(uid_t ruid, uid_t euid, uid_t suid);
In file included from main.cxx::
/mnt/usr/include/unistd.h:: error: from previous declaration int setresuid(__uid_t, __uid_t, __uid_t) throw ()
extern int setresuid (__uid_t __ruid, __uid_t __euid, __uid_t __suid)
In file included from ../perlapi/perl.h::,
from ../perlapi/Utils.h:,
from main.cxx::
/archive/webql/build/al/current/base/dev/perl/core/perl.h: error: declaration of int setresgid(gid_t, gid_t, gid_t) has a different exception specifier
int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
In file included from main.cxx::
/mnt/usr/include/unistd.h:: error: from previous declaration int setresgid(__gid_t, __gid_t, __gid_t) throw ()
extern int setresgid (__gid_t __rgid, __gid_t __egid, __gid_t __sgid)
make: Leaving directory `/archive/webql/build/al/current/base/dev/webql'
Things tried
Re compiled the boost 1.42 and other dependencies
Expectation
Even after trying several things the error remains same. perl.h is part of project code while unistd.h is a system file. Obviously perl.h is C code hence it cannot THROW exception as present in unstd.h function declaration.
Any help would be appreciated.

class std::auto_ptr’ is deprecated while trying to compile with mysql++ library

I'm facing a compilation problem while trying to use mysql++.h in my C++ program on an ASUS Tinker Board.
Includes look like this :
#include <mysql++.h>
#include <stdlib.h>
G++ command executed is this one :
g++ -I/usr/include/mysql -I/usr/include/mysql++ -L/usr/lib -lmysqlpp -lmysqlclient mysql.c -o mysql
Output contains the following :
In file included from /usr/include/mysql++/sql_buffer.h:31:0,
from /usr/include/mysql++/stadapter.h:35,
from /usr/include/mysql++/qparms.h:35,
from /usr/include/mysql++/query.h:35,
from /usr/include/mysql++/mysql++.h:58,
from mysql.c:1:
/usr/include/mysql++/refcounted.h: In constructor ‘mysqlpp::RefCountedPointer<T, Destroyer>::RefCountedPointer(T*)’:
/usr/include/mysql++/refcounted.h:104:8: warning: ‘template<class> class std::auto_ptr’ is deprecated [-Wdeprecated-declarations]
std::auto_ptr<T> exception_guard(counted_);
^~~~~~~~
In file included from /usr/include/c++/6/memory:81:0,
from /usr/include/mysql++/refcounted.h:31,
from /usr/include/mysql++/sql_buffer.h:31,
from /usr/include/mysql++/stadapter.h:35,
from /usr/include/mysql++/qparms.h:35,
from /usr/include/mysql++/query.h:35,
from /usr/include/mysql++/mysql++.h:58,
from mysql.c:1:
/usr/include/c++/6/bits/unique_ptr.h:49:28: note: declared here
template<typename> class auto_ptr;
^~~~~~~~
I tried to modify file "/refcounted.h" by changing "std::auto_ptr" by "std::unique_ptr", it compiles successfully, but I get a "Segmentation fault" while trying to run my program.
Please help, thanks.

clang++ only compiles C++11 program using boost::format when -std=c++11 option is dropped

Please take a look at the following C++11 snippet:
#include <boost/format.hpp>
int main(int argc, char** argv)
{
auto s = boost::format("");
return 0;
}
When I compile it with clang using the -std=c++11 I get the following error:
$ clang++ -std=c++11 -o main main.cpp
In file included from main.cpp:1:
In file included from /usr/include/boost/format.hpp:19:
In file included from /usr/include/boost/detail/workaround.hpp:41:
In file included from /usr/include/boost/config.hpp:40:
In file included from /usr/include/boost/config/select_stdlib_config.hpp:18:
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/cstddef:51:11: error:
no member named 'max_align_t' in the global namespace
using ::max_align_t;
~~^
1 error generated.
Without the -std=c++11 everything compiles fine, but clang prints a warning:
$ clang++ -o main main.cpp
main.cpp:5:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto s = boost::format("");
^
So, it looks like a valid workaround is to drop the C++11 flag, as the current version of clang seem to be in C++11 mode, anyway? The drawback is that you will get many warnings.
Is there a better workaround beside completely switching to gcc? Patching the source code of boost::format or gcc-libs is fine for me.
System information:
Platform: Arch Linux x86_64
Boost version: 1.55.0-6
gcc-libs: 4.9.0-1
clang++: 3.4 (tags/RELEASE_34/final)
The bug is closed now. It should be fixed in Arch with clang 3.4-2.
With this commit, Evangelos Foutras merged the following patch from upstream:
http://reviews.llvm.org/rL201729

cross compile c++ on linux to windows

clang++ main.cpp -std=c++11 -target x86_64-unknown-win32 -I/usr/lib/gcc/x86_64-w64-mingw32/4.6/include/
main.cpp:6:10: fatal error: 'string' file not found
#include <string>
^
1 error generated.
that's weird because:
/usr/lib/gcc/x86_64-w64-mingw32/4.6/include/ssp$ ls
ssp.h stdio.h string.h unistd.h
and this result the same:
clang++ main.cpp -std=c++11 -target x86_64-unknown-win32 -I/usr/lib/gcc/x86_64-w64-mingw32/4.6/include/ssp
well. I used to compile c code from linux to windows just fine using:
x86_64-w64-mingw32-gcc main.c
and I tried:
x86_64-w64-mingw32-g++ -std=c++0x main.cpp
also:
x86_64-w64-mingw32-g++ -std=c++0x main.cpp -I/usr/lib/gcc/x86_64-w64-mingw32/4.6/include
still give bunch of errors like
main.cpp:70:23: sorry, unimplemented: non-static data member initializers
main.cpp:70:23: error: in-class initialization of static data member ‘origin’ of non-literal type
main.cpp: In constructor ‘Item::Item(std::string)’:
main.cpp:83:18: error: ‘stoul’ is not a member of ‘std’
main.cpp:88:4: error: ‘origin’ was not declared in this scope
main.cpp:89:17: error: ‘stof’ is not a member of ‘std’
main.cpp: In function ‘std::ostream& operator<<(std::ostream&, const Item&)’:
....
x86_64-w64-mingw32-g++ (GCC) 4.6.3 seems to be the latest version on ubuntu repo.
I'm at lost..why the hell clang won't use the headers. why the hell x86_64-w64-mingw32-g++ won't listen that it should use c++11 standards.
The GCC version you use does not support non-static data member initializers as shown here. Find out here which version of GCC supports the C++11 feature set you required.