I'm trying to compile a simple example in Turtle (with boost unit test framework) and am getting compilation errors from within Turtle.
I'm assuming that Turtle doesn't really have errors and it's something that I'm doing wrong or have incompatible.
Any help would be appreciated.
The example:
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <turtle/mock.hpp>
BOOST_AUTO_TEST_CASE(trutletest){
BOOST_CHECK(1 == 4);
}
** I've distilled it so it doesn't even uses any Turtle features, just including it causes errors.
The errors I get:
In file included from ../turtle/include/turtle/detail/../matcher.hpp:14,
from ../turtle/include/turtle/detail/function.hpp:16,
from ../turtle/include/turtle/detail/functor.hpp:12,
from ../turtle/include/turtle/reset.hpp:14,
from ../turtle/include/turtle/mock.hpp:14,
from test.cpp:5:
../turtle/include/turtle/detail/../detail/is_functor.hpp:22: error: expected constructor, destructor, or type conversion before ‘(’ token
In file included from ../turtle/include/turtle/detail/function.hpp:16,
from ../turtle/include/turtle/detail/functor.hpp:12,
from ../turtle/include/turtle/reset.hpp:14,
from ../turtle/include/turtle/mock.hpp:14,
from test.cpp:5:
../turtle/include/turtle/detail/../matcher.hpp:87: error: ‘is_functor’ is not a member of ‘mock::detail’
../turtle/include/turtle/detail/../matcher.hpp:87: error: ‘is_functor’ is not a member of ‘mock::detail’
../turtle/include/turtle/detail/../matcher.hpp:87: error: template argument 1 is invalid
../turtle/include/turtle/detail/../matcher.hpp:88: error: template argument 3 is invalid
../turtle/include/turtle/detail/../matcher.hpp:89: error: expected unqualified-id before ‘>’ token
The compilation line:
g++ test.cpp -o test -I ../turtle/include/ -lboost_unit_test_framework
I'm using:
g++ (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4)
Turtle 1.2.4
As cv_and_he commented, the problem was using an old boost version.
Updating to the latest boost (1.54.0) fixed the problem.
Related
im trying to build the example here https://github.com/jtv/libpqxx#programming-with-libpqxx using c++ compiler on my beagleboneblack, ececuting the command: g++ -o taks tasks.cpp -lpqxx -lpq
I belive i have installed the lpqxx library with success.
Gcc compiler version: gcc (Debian 8.3.0-6) 8.3.0
When compiling i get the following errors (and several other not show here):
warning: structured bindings only available with -std=c++17 or -std=gnu++17
for (auto [name, salary] : tx.query<std::string, int>(
^
tasks.cpp:20:43: error: ‘using work = class pqxx::transaction<>’ {aka ‘class pqxx::transaction<>’} has no member named ‘query’
for (auto [name, salary] : tx.query<std::string, int>(
^~~~~
tasks.cpp:20:60: error: expected primary-expression before ‘,’ token
The first is a warning, but the others error. Not familiar with C#:
What does these errors mean?
How do i get on solving them?
Is it compiler issues or is it code issues?
I just have one file in my direcory and that is copy-paste of the example from the link, am i missing some header files that define some stuff for me?
I am trying to compile par2tbb on Gentoo Linux kernel 3.18.12, and I keep getting the following compilation error:
par2cmdline.cpp: In function ‘int main(int, char**)’:
par2cmdline.cpp:88:3: error: ‘auto_ptr’ is not a member of ‘std’
std::auto_ptr<CommandLine> commandline(new CommandLine);
^
I already checked that #include <memory.h> was present on the source code, I already added CXXFLAGS = -std=c++11 to the makefile, and it still won't compile.
Looking up online, these two measures are the only fixes I could find. Any idea on what's going on?
I've just installed a clean vm with xubuntu 12.10 and I'm trying to port over some C++ code which works perfectly on Windows. First off, I've installed Virtualbox guest additions and GCC and I can compile code.
I've downloaded the boost library from the internet (boost_1_52) and I've dropped in the asio library from the asio website (boost_asio_1_4_8) and I've installed the multi-threading, shared link version using these instructions:
./bootstrap.sh --prefix=/usr &&
./b2 stage threading=multi link=shared
as root:
I know for a fact that boost works because I've been able to compile the test application here (linking with lboost_regex) and it works perfectly:
#include <boost/regex.hpp>
#include <iostream>
#include <string>
int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}
So I'm trying to build one of the ASIO examples, which I've built before with no problems on Windows. The files are here:
http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/examples.html
See:
boost_asio/example/serialization/client.cpp
boost_asio/example/serialization/connection.hpp
boost_asio/example/serialization/server.cpp
boost_asio/example/serialization/stock.hpp
I throw my compiler this:
gcc client.cpp -I /usr/include/boost -lboost_system -lboost_thread -lboost_serialization
Which gives me this error:
connection.hpp:75:35: error: template argument 1 is invalid
connection.hpp:75:35: error: template argument 2 is invalid
connection.hpp:75:44: error: invalid type in declaration before ‘;’ token
connection.hpp:76:13: error: request for member ‘push_back’ in ‘buffers’, which is of non-class type ‘int’
connection.hpp:76:23: error: ‘asio’ is not a class or namespace
connection.hpp:77:13: error: request for member ‘push_back’ in ‘buffers’, which is of non-class type ‘int’
connection.hpp:77:23: error: ‘asio’ is not a class or namespace
connection.hpp:78:5: error: ‘asio’ is not a class or namespace
connection.hpp:78:23: error: ‘socket_’ was not declared in this scope
connection.hpp: In member function ‘void s11n_example::connection::async_read(T&, Handler)’:
connection.hpp:87:15: error: ‘asio’ does not name a type
connection.hpp:87:31: error: expected unqualified-id before ‘&’ token
connection.hpp:87:31: error: expected ‘)’ before ‘&’ token
connection.hpp:87:31: error: expected initializer before ‘&’ token
connection.hpp:90:5: error: ‘asio’ has not been declared
connection.hpp:90:22: error: ‘socket_’ was not declared in this scope
connection.hpp:90:31: error: ‘asio’ has not been declared
connection.hpp:91:21: error: ‘f’ was not declared in this scope
connection.hpp:92:17: error: ‘asio’ has not been declared
client.cpp: At global scope:
client.cpp:26:10: error: ‘asio’ has not been declared
client.cpp:26:26: error: expected ‘)’ before ‘&’ token
client.cpp:43:29: error: ‘asio’ does not name a type
client.cpp:43:45: error: expected unqualified-id before ‘&’ token
client.cpp:43:45: error: expected ‘)’ before ‘&’ token
client.cpp:43:35: error: expected ‘;’ at end of member declaration
client.cpp:43:47: error: ISO C++ forbids declaration of ‘e’ with no type [-fpermissive]
client.cpp:43:47: error: expected ‘;’ at end of member declaration
client.cpp:43:48: error: expected unqualified-id before ‘)’ token
client.cpp:125:1: error: expected ‘}’ at end of input
client.cpp:125:1: error: expected unqualified-id at end of input
client.cpp:125:1: error: expected ‘}’ at end of input
I'm really confused, its as if I've not built boost or I'm missing another link. I've also tried linking with Winsock, with no results. Please help!
Cheers
You are using gcc and g++ interchangeably. The line which doesn't work uses gcc, but the line which works uses g++. Using g++ instead of gcc may effect which default include path is used. Your initial error was not linking. It was compiling. Also, if you use the boost version, asio namespace is not asio. It's boost::asio.
Looks like boost/asio.hpp didn't get included correctly.
I don't remember exactly what the prefix option does, but I think your problem may be somewhere in there. The boost directory may not be in /usr/include/boost, but instead possibly /usr/boost.
That's one possibility. The second is that, instead of passing /usr/include/boost, you need to pass /usr/include, i.e.
gcc client.cpp -I /usr/include -lboost_system -lboost_thread -lboost_serialization
If you look at the example files, e.g. the connection.cpp example, it includes boost/asio.hpp. The boost/ part refers to a folder that should be looked for by the compiler in the include path(s) you specify using -I. So if you specified /usr/include/boost, the compiler is going to look for /usr/include/boost/boost/asio.hpp (notice the 2 occurrences of boost).
I think I've fixed the problem now. Using bjam and the auto-installer doesn't seem to accomplish much (it won't resolve to those paths for some reason).
Anyway, I downloaded the ASIO source code (non-boost this time) and put that in a directory on my desktop. In a similar fashion to how I do it on windows in Visual Studio, I managed to get it to link:
g++ client.cpp -I/home/devbox/desktop/asio-1.5.3/include - L/home/devbox/Desktop/boost_1_53_0/stage/lib -lboost_system -lboost_thread -lboost_serialization -o test
Cheers all
I am using CUDA 4.1 and GCC 4.5 ... (FINALLY! CUDA supports GCC 4.5, but still waiting for GCC 4.6). Anyways, is it possible to use C++11 with the CUDA 4.1?
I tried passing:
--compiler-options "-std=c++0x"
to nvcc and it throws a bunch of errors at me:
/usr/include/c++/4.5/exception_ptr.h(100): error: copy constructor for class "std::__exception_ptr::exception_ptr" may not have a parameter of type "std::__exception_ptr::exception_ptr"
/usr/include/c++/4.5/exception_ptr.h(100): error: expected a ")"
/usr/include/c++/4.5/exception_ptr.h(110): error: expected a ")"
/usr/include/c++/4.5/exception_ptr.h(132): error: identifier "type_info" is undefined
/usr/include/c++/4.5/exception_ptr.h(101): error: identifier "__o" is undefined
/usr/include/c++/4.5/exception_ptr.h(112): error: expected a ">"
/usr/include/c++/4.5/exception_ptr.h(112): error: identifier "__o" is undefined
/usr/include/c++/4.5/nested_exception.h(62): error: expected a ";"
/usr/include/c++/4.5/nested_exception.h(64): error: expected a ";"
/usr/include/c++/4.5/nested_exception.h(77): error: member function "std::nested_exception::~nested_exception" may not be redeclared outside its class
/usr/include/c++/4.5/nested_exception.h(77): error: function "std::<error>" may not be initialized
/usr/include/c++/4.5/nested_exception.h(77): error: expected an expression
/usr/include/c++/4.5/nested_exception.h(82): error: expected a ")"
/usr/include/c++/4.5/nested_exception.h(110): error: expected a ")"
/usr/include/c++/4.5/nested_exception.h(115): error: expected a ")"
/usr/include/c++/4.5/nested_exception.h(122): error: expected a ")"
/usr/include/c++/4.5/nested_exception.h(127): error: expected a ")"
/usr/include/c++/4.5/nested_exception.h(127): error: function template "std::__throw_with_nested" has already been defined
/usr/include/c++/4.5/bits/cpp_type_traits.h(180): error: identifier "char16_t" is undefined
/usr/include/c++/4.5/bits/cpp_type_traits.h(187): error: identifier "char32_t" is undefined
/usr/include/c++/4.5/bits/cpp_type_traits.h(187): error: class "std::__is_integer<<error-type>>" has already been defined
21 errors detected in the compilation of "/tmp/tmpxft_00000ef2_00000000-4_test_cuda.cpp1.ii".
Example test.cu
#include <cuda.h>
__host__ void test() {
// nothing in method
}
Compiles fine with:
nvcc -c -o test.o test.cu
But not with C++0x
nvcc -c -o test.o test.cu --compiler-options "-std=c++0x"
No, as of this answer, nvcc does not support c++11 constructs, even if they are supported by the host compiler.
The reason it isn't as simple as passing -std=c++0x to the host compiler is that nvcc has to parse the entirety of the code in order to split it into its __host__and __device__ halves. This preprocess happens before the host compiler is presented with any code at all, so nvcc's parser needs to be able to grok c++11 for it to work.
Update on #Jared Hoberock's answer based on another message he posted on Thrust's Google Group: it seems that C++11 support has been added to CUDA 6.5 (although it is still experimental and undocumented).
Dummy example: test.cu
#include <cuda.h>
#include <iostream>
__host__ void test() {
float a = 12.;
double b = 3.;
auto c = a * b;
std::cout << c << std::endl;
}
int main()
{
test();
return 0;
}
Compilation & execution
$ nvcc -std=c++11 test.cu -o test
$ ./test
36
Without -std=c++11, I get the following (expected) error:
test.cu(7): error: explicit type is missing ("int" assumed)
Note: this example may fail to compile with GCC 5.1.
Update
CUDA 7.0 officially introduced C++11 support:
CUDA 7 adds C++11 feature support to nvcc, the CUDA C++ compiler. This means that you can use C++11 features not only in your host code compiled with nvcc, but also in device code. New C++ language features include auto, lambda functions, variadic templates, static_assert, rvalue references, range-based for loops, and more. To enable C++11 support, pass the flag --std=c++11 to nvcc (this option is not required for Microsoft Visual Studio).
I get the following error when compiling this third-party library (called azove 2.0) which relies on the GNU Multi-precision library:
> make
g++ -Wall -O3 -DFIX_NUMBER_OF_SIGMDDNODE_SONS -DUSE_TIMER -I. -c conBDD.cpp -o conBDD.o
In file included from conBDDnode.hpp:27,
from conBDD.hpp:25,
from conBDD.cpp:22:
/usr/include/gmpxx.h: In destructor ‘__gmp_alloc_cstring::~__gmp_alloc_cstring()’:
/usr/include/gmpxx.h:2096: error: ‘strlen’ was not declared in this scope
conBDD.cpp: In member function ‘void conBDD::build()’:
conBDD.cpp:61: error: ‘numeric_limits’ was not declared in this scope
conBDD.cpp:61: error: expected primary-expression before ‘int’
conBDD.cpp:61: error: expected `;' before ‘int’
conBDD.cpp:68: error: expected primary-expression before ‘int’
conBDD.cpp:68: error: expected `;' before ‘int’
make: *** [conBDD.o] Error 1
I have tried adding either and both of the following lines
#include <cstdlib>
using std::strlen;
to conBDD.cpp, but the error persists.
I can't tell if this is an error comes from GNU's Multi-precision library or from Azove. Any pointers would be greatly appreciated.
I would start by apportioning blame. Create an empty cpp file, say test.cpp, in your project and include only the offending gmpxx.h file. If you can compile test cpp, GMP is off the hook. Then try including only the offending azove header. If you can compile the azove header in an otherwise empty file, azove is off the hook and something you are including/defining is interfering with them. Once you have narrowed down the source of the problem you should find it easier to fix.