MinGw 4.7.0 Boost 1.47
code:
#include <iostream>
#include <boost/thread.hpp>
int main(int argc, char *argv[])
{
std::cout<<"In main"<<std::endl;
}
Compiler string:
g++.exe -Wall -fexceptions -g -IC:\soft\ides_comp\mingw\include\boost_1_47_0 -c D:\work\cpp_cb\mt1\main.cpp -o obj\Debug\main.o
It doesnt compile and i have same error whatever compiler options i tried.
Warning:
In file included from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_data.hpp:12:0,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread.hpp:15,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread.hpp:13,
from D:\work\cpp_cb\mt1\main.cpp:2:
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_heap_alloc.hpp:59:40: warning: inline function 'void* boost::detail::allocate_raw_heap_memory(unsigned int)' declared as dllimport: attribute ignored [-Wattributes]
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_heap_alloc.hpp:69:39: warning: inline function 'void boost::detail::free_raw_heap_memory(void*)' declared as dllimport: attribute ignored [-Wattributes]
Error:
In file included from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/shared_ptr.hpp:30:0,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/shared_ptr.hpp:17,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/date_time/time_clock.hpp:17,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread_time.hpp:9,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_data.hpp:10,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread.hpp:15,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread.hpp:13,
from D:\work\cpp_cb\mt1\main.cpp:2:
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/checked_delete.hpp: In instantiation of 'void boost::checked_delete(T*) [with T = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]':
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/detail/shared_count.hpp:95:13: required from 'boost::detail::shared_count::shared_count(Y*) [with Y = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]'
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/shared_ptr.hpp:183:50: required from 'boost::shared_ptr<T>::shared_ptr(Y*) [with Y = boost::error_info<boost::tag_original_exception_type, const std::type_info*>; T = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]'
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/info.hpp:171:69: required from 'const E& boost::exception_detail::set_info(const E&, const boost::error_info<Tag, T>&) [with E = boost::unknown_exception; Tag = boost::tag_original_exception_type; T = const std::type_info*]'
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/info.hpp:192:46: required from 'typename boost::enable_if<boost::exception_detail::derives_boost_exception<E>, const E&>::type boost::operator<<(const E&, const boost::error_info<Tag, T>&) [with E = boost::unknown_exception; Tag = boost::tag_original_exception_type; T = const std::type_info*; typename boost::enable_if<boost::exception_detail::derives_boost_exception<E>, const E&>::type = const boost::unknown_exception&]'
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/detail/exception_ptr.hpp:182:13: required from 'void boost::unknown_exception::add_original_type(const E&) [with E = std::exception]'
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/detail/exception_ptr.hpp:161:32: required from here
Warning 2:
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/checked_delete.hpp:34:5: warning: deleting object of polymorphic class type 'boost::error_info<boost::tag_original_exception_type, const std::type_info*>' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
What can it be? Thanks
This has been fixed in later boost versions. Check here:
https://svn.boost.org/trac/boost/ticket/6165
Update boost/config/stdlib/libstdcpp3.hpp:
#if defined(_GLIBCXX_HAVE_GTHR_DEFAULT) \
|| defined(_GLIBCXX_HAS_GTHREADS) \
|| defined(_GLIBCXX__PTHREADS) \
|| defined(WIN32)
Added _GLIBCXX_HAS_GTHREADS and/or WIN32 (from the link above, see patch).
WIN32 seems a bit brute force, but doesn't work without (at least not for me. I am using an older boost version 1.42).
If you compiled the thread library for using Win32 threads, you might need
-DBOOST_USE_WINDOWS_H
in your compiler flags. While I don't think that's the issue (I get a different set of errors for not using it), you might give it a try.
This answer maybe not very straight, but:
I do use g++ 4.7.0 20111209 and it has support for threads.
#include <iostream>
#include <thread>
using namespace std;
void foo()
{
cout << "Hello from thread\n";
}
int main()
{
thread th1(foo);
th1.join();
return 0;
}
During compilation use -std=c++11 option to use the latest standard which supports threads
PS:
boost 1.48 compiled on my pc with mingw 4.7.0 gives an error (when trying to use boost::thread):
Threading support unavailable: it has been explicitly disabled with BOOST_DISABLE_THREADS
So I guess it was disabled by default with g++ 4.7.0 (with g++ 4.6.2 it was not).
Related
I install the xtensor by conda
conda install -c conda-forge xtensor
and I find the position where the xtensor is installed,
path_xtensor="/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/"
path_xtl="/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/"
the first example is given by the xtensor docs,
i.e.
#include <iostream>
#include <xtensor/xarray.hpp>
#include <xtensor/xio.hpp>
#include <xtensor/xview.hpp>
int main(int argc, char* argv[])
{
xt::xarray<double> arr1
{{1.0, 2.0, 3.0},
{2.0, 5.0, 7.0},
{2.0, 5.0, 7.0}};
xt::xarray<double> arr2
{5.0, 6.0, 7.0};
xt::xarray<double> res = xt::view(arr1, 1) + arr2;
std::cout << res << std::endl;
return 0;
}
I followed that and run the command in linux servers
g++ -I path_xtensor -I path_xtl x.cpp -o x
but the command cause error, the log is too long, the following is partly:
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:931:63: error: ‘int xt::xfunction_iterator<F, CT>::deref_impl’ is not a static data member of ‘class xt::xfunction_iterator<F, CT>’
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:931:63: error: template definition of non-template ‘int xt::xfunction_iterator<F, CT>::deref_impl’
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:931:58: error: ‘index_sequence’ is not a member of ‘std’
inline auto xfunction_iterator<F, CT...>::deref_impl(std::index_sequence<I...>) const -> reference
^
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:936:29: warning: variadic templates only available with -std=c++11 or -std=gnu++11
template <class F, class... CT>
^
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:937:30: warning: variadic templates only available with -std=c++11 or -std=gnu++11
template <std::size_t... I>
^
...
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp: In member function ‘void xt::xfunction_stepper<F, CT>::step_leading()’:
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:1058:14: error: ‘ame a type
virtual const char what() const noexcept override { return "bad_variant_access"; }
^
/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant_impl.hpp:914:38: note: C++11 ‘noexcept’ only available with -std=c++11 or -std=gnu++11
/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant_impl.hpp:914:25: error: looser throw specifier for ‘virtual const char mpark::bad_variant_access::what() const’
virtual const char what() const noexcept override { return "bad_variant_access"; }
^
In file included from /usr/include/c++/5/ios:39:0,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from x.cpp:24:
/usr/include/c++/5/exception:68:25: error: overriding ‘virtual const char std::exception::what() const throw ()’
virtual const char* what() const _GLIBCXX_USE_NOEXCEPT;
^
In file included from /amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant.hpp:13:0,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xstrided_view.hpp:20,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xgenerator.hpp:27,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xbuilder.hpp:31,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xmanipulation.hpp:13,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xmath.hpp:28,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xcontainer.hpp:25,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xarray.hpp:20,
from x.cpp:25:
/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant_impl.hpp:917:3: error: expected unqualified-id before ‘[’ token
[[noreturn]] inline void throw_bad_variant_access() {
^
x.cpp:38:1: error: expected ‘}’ at end of input
}
Thanks in advance for any help/suggestion.
Is the following command the full command line you execute?
g++ -I path_xtensor -I path_xtl x.cpp -o x
Then it is missing two helpful options:
To ensure the compiler is using a modern c++ standard, add an option like -std=c++11 or -std=c++14 or even newer standards, depending what your compiler supports and what you want to use in the remainder of your project. xtensor requires at least c++11.
To ensure that the compiler will use good CPU optimizations for the binary, add flags that enable general performance optimizations like -O2 and specific hardware optimizations for your current CPU like -march=native, unless you want your resulting binary to be portable to other computers (with a less modern CPU). This can give an huge performance boost with xtensor.
Does that help?
I am unable to compile a basic boost vector example.
I am on Windows 10, and I am using the nuwen MinGW distro version 15.0, without git included. This version contains GCC 7.10 and Boost 1.64. I have unpacked MinGw and placed it in the root of my file system and I am following the MinGW usage instruction A to run set_distro_paths.bat. Below is the code, which is failing to build on my system:
vector-fail.cpp:
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v (3);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;
std::cout << v << std::endl;
}
Makefile:
vector-fail: vector-fail.o
g++ vector-fail.o -o vector-fail
vector-fail.o: vector-fail.cpp
g++ -c vector-fail.cpp -o vector-fail.o
Output:
g++ -c vector-fail.cpp -o vector-fail.o
In file included from C:\MinGW\include/boost/numeric/ublas/vector.hpp:21:0,
from vector-fail.cpp:1:
C:\MinGW\include/boost/numeric/ublas/storage.hpp: In member function 'void
boost::numeric::ublas::unbounded_array<T, ALLOC>::serialize(Archive&, unsigned int)':
C:\MinGW\include/boost/numeric/ublas/storage.hpp:299:33: error: 'make_array' is not a member of 'boost::serialization'
ar & serialization::make_array(data_, s);
^~~~~~~~~~
C:\MinGW\include/boost/numeric/ublas/storage.hpp:299:33: note: suggested alternative: 'make_nvp'
ar & serialization::make_array(data_, s);
^~~~~~~~~~
make_nvp
C:\MinGW\include/boost/numeric/ublas/storage.hpp: In member function 'void boost::numeric::ublas::bounded_array<T, N, ALLOC>::serialize(Archive&, unsigned int)':
C:\MinGW\include/boost/numeric/ublas/storage.hpp:494:33: error: 'make_array' is not a member of 'boost::serialization'
ar & serialization::make_array(data_, s);
^~~~~~~~~~
C:\MinGW\include/boost/numeric/ublas/storage.hpp:494:33: note: suggested alternative: 'make_nvp'
ar & serialization::make_array(data_, s);
^~~~~~~~~~
make_nvp
make: *** [Makefile:5: vector-fail.o] Error 1
Unfortunately none of those errors are occurring within my code, rather they are caused by files within include files within the boost library its self. What changes could be made in application level code or the Makefile to allow the program to compile?
Yes this is an issue with the ublas headers. I ran into it before. You can workaround it by including
#include <boost/serialization/array_wrapper.hpp>
before that point though. I'd consider reporting it to the maintainers of the ublas code.
I've been learning C++ and using the Terminal for the last couple of months. My code was compiling and running fine using g++ and C++11, but in the last couple of days it started giving errors and I have had problems compiling since. The only programs I can compile and run depend on older C++ standards.
The errors I first got related to #include < array > in the header file. Not sure why this happened, but I got around it by using boost/array instead. Another error I can't solve is with std::stoi. Both array and stoi should be in the C++11 standard library. I made the following simple code to demonstrate what's going on:
//
// stoi_test.cpp
//
// Created by ecg
//
#include <iostream>
#include <string> // stoi should be in here
int main() {
std::string test = "12345";
int myint = std::stoi(test); // using stoi, specifying in standard library
std::cout << myint << '\n'; // printing the integer
return(0);
}
Try to compile using ecg$ g++ -o stoi_trial stoi_trial.cpp -std=c++11
array.cpp:13:22: error: no member named 'stoi' in namespace 'std'; did you mean
'atoi'?
int myint = std::stoi(test);
~~~~~^~~~
atoi
/usr/include/stdlib.h:149:6: note: 'atoi' declared here
int atoi(const char *);
^
array.cpp:13:27: error: no viable conversion from 'std::string' (aka
'basic_string') to 'const char *'
int myint = std::stoi(test);
^~~~
/usr/include/stdlib.h:149:23: note: passing argument to parameter here
int atoi(const char *);
^
2 errors generated.
I also get these errors at compilation when using gcc or clang++ and with -std=gnu++11 (I guess they all depend on the same file structure). I also get the same error whether I specify std:: in the code, or if I specify using namespace std;
I worry that these issues arose because of the September Command Line Tools update via Xcode or because I installed boost and this somehow messed up my C++11 libraries. Hopefully there is a simple solution.
My system:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-> dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.76) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
Thanks for any insight you can offer.
clang has a weird stdlib, you need to add the following flag when you compile
-stdlib=libc++
your snippet works on my mac with
g++ -std=gnu++11 -stdlib=libc++ test.cpp -o test
This answer describes the problem
I try to compile the simple code
#include <atomic>
int bar = 0;
void foo(std::atomic<int>&flag)
{ bar = flag; }
with clang++ 3.2 (downloaded as llvm 3.2 from llvm.org; on mac os.x 10.8.3 this fails with the error
/> clang++ -std=c++11 -stdlib=libc++ -O3 -march=native -c test.cc
In file included from test.cc:1:
/usr/include/c++/v1/atomic:576:17: error: first argument to atomic operation must be a pointer to non-const _Atomic type ('const _Atomic(int) *' invalid)
{return __c11_atomic_load(&__a_, __m);}
^ ~~~~~
/usr/include/c++/v1/atomic:580:53: note: in instantiation of member function
'std::_1::_atomic_base::load' requested here
operator _Tp() const _NOEXCEPT {return load();}
^
test.cc:5:9: note: in instantiation of member function 'std::_1::_atomic_base::operator int' requested here
bar = done;
When I use /usr/bin/clang++ instead (which comes with the OS or Xcode) it compiles just fine. The libc++ is that at /usr/lib/c++/v1 in both cases.
What am I missing? Is there another libc++ that comes with llvm 3.2 but which I'm missing? (I cannot find anything in the clang3.2 tree).
Xcode now bundles libc++ within the Xcode.app directory. You can inspect this directory by control-clicking Xcode.app and choose "Show Package Contents".
#include <string>
#include <tr1/regex>
#include "TextProcessing.h"
const std::string URL_PATTERN("((http://)[-a-zA-Z0-9#:%_\\+.~#?&//=]+)");
const std::string REPLACEMENT("$&");
std::string textprocessing::processLinks(const std::string & text)
{
// essentially the same regex as in the previous example, but using a dynamic regex
std::tr1::regex url(URL_PATTERN);
// As in Perl, $& is a reference to the sub-string that matched the regex
return std::tr1::regex_replace(text, url, REPLACEMENT);
}
I'm using mingw gcc copiler 4.5.0 version.
I've got the follow error:
%DEV%> mingw32-make all
g++ -Wl,--enable-auto-import -Wall -Wextra -std=c++0x -pedantic -Werror -c -I./include TextProcessing.cpp
cc1plus.exe: warnings being treated as errors
c:\dev\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/tr1_impl/regex:2390:5: error: inline function '_Out_iter std::tr1::regex_replace(_Out_iter, _Bi_iter, _Bi_iter, const std::tr1::basic_regex<_Ch_type, _Rx_traits>&, const std::basic_string<_Ch_type>&, std::tr1::regex_constants::match_flag_type) [with _Out_iter = std::back_insert_iterator<std::basic_string<char> >, _Bi_iter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, _Rx_traits = std::tr1::regex_traits<char>, _Ch_type = char, std::tr1::regex_constants::match_flag_type = std::bitset<11u>]' used but never defined
mingw32-make: *** [TextProcessing.o] Error 1
Process mingw32-make exited with code 2
Yup, in my g++ include files I also see that regex_replace is declared and not defined. For me, it's in the file /usr/include/c++/4.4.4/tr1_impl/regex . Just above the declaration is a Doxygen comment section which includes:
/** #todo Implement this function. */
Your standard C++ library does not have complete c++0x (now c++1x?) support. Try using Boost's code. See also this answer.