MinGw 4.7.0 不使用 #include 编译代码

发布于 2024-12-17 18:57:21 字数 4283 浏览 3 评论 0 原文

MinGw 4.7.0 增强版 1.47
代码:

#include <iostream>
#include <boost/thread.hpp>
int main(int argc, char *argv[])
{
std::cout<<"In main"<<std::endl;
}

编译器字符串:

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

它无法编译,无论我尝试什么编译器选项,我都会遇到相同的错误。

警告:
在 C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_data.hpp:12:0 包含的文件中, 来自 C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread.hpp:15, 来自 C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread.hpp:13, 来自 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:警告:内联函数 'void* boost::detail::allocate_raw_heap_memory(unsigned int)' 声明为 dllimport:属性被忽略 [-Wattributes] C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_heap_alloc.hpp:69:39:警告:内联函数'void boost::detail::free_raw_heap_memory(void*)'声明为dllimport:属性忽略 [-Wattributes]

错误:
在 C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/shared_ptr.hpp:30:0 包含的文件中, 来自 C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/shared_ptr.hpp:17, 来自 C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/date_time/time_clock.hpp:17, 来自 C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread_time.hpp:9, 来自 C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_data.hpp:10, 来自 C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread.hpp:15, 来自 C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread.hpp:13, 来自 D:\work\cpp_cb\mt1\main.cpp:2:

C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/checked_delete.hpp: 在 'void boost::checked_delete(T*) 的实例化中 [with T = boost::error_info]':


C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/detail/shared_count.hpp:95:13:需要来自 'boost::detail::shared_count::shared_count(Y*) [与 Y = boost::error_info]' C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/shared_ptr.hpp:183:50: 需要 'boost::shared_ptr::shared_ptr(Y*) [其中 Y = boost::error_info< ;boost::tag_original_exception_type, const std::type_info*>; T = boost::error_info]' C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/info.hpp:171:69:需要来自 'const E& boost::exception_detail::set_info(const E&, const boost::error_info&) [其中 E = boost::unknown_exception;标签 = 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:从 'typename boost::enable_if 需要,const E> ::type boost::operator<<(const E&, const boost::error_info&) [其中 E = boost::unknown_exception;标签 = boost::tag_original_exception_type; T = const std::type_info*;类型名 boost::enable_if, 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: 需要 'void boost::unknown_exception::add_original_type(const E&) [with E = std::例外]' C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/detail/exception_ptr.hpp:161:32:此处需要

警告 2:
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/checked_delete.hpp:34:5: 警告:删除多态类类型 'boost::error_info'具有非虚拟析构函数可能会导致未定义的行为 [-Wdelete-non-virtual-dtor]

它会是什么?谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

感悟人生的甜 2024-12-24 18:57:21

这已在后续的 boost 版本中得到修复。检查此处:

https://svn.boost.org/trac/boost/ticket/6165< /a>

更新 boost/config/stdlib/libstdcpp3.hpp:

#if defined(_GLIBCXX_HAVE_GTHR_DEFAULT) \
    || defined(_GLIBCXX_HAS_GTHREADS) \
    || defined(_GLIBCXX__PTHREADS) \
    || defined(WIN32)

添加了 _GLIBCXX_HAS_GTHREADS 和/或 WIN32(从上面的链接,请参阅补丁)。

WIN32 似乎有点暴力,但没有它就无法工作(至少对我来说不是。我使用的是较旧的 bo​​ost 版本 1.42)。

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).

梦萦几度 2024-12-24 18:57:21

如果您编译了使用 Win32 线程的线程库,则可能需要

-DBOOST_USE_WINDOWS_H

在编译器标志中添加。虽然我不认为这是问题(我因不使用它而收到一组不同的错误),但您可以尝试一下。

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.

泪冰清 2024-12-24 18:57:21

这个答案可能不是很直接,但是:
我确实使用 g++ 4.7.0 20111209 并且它支持线程。

#include <iostream>
#include <thread>

using namespace std;

void foo()
{
    cout << "Hello from thread\n";
}

int main()
{
    thread th1(foo);
    th1.join();
    return 0;
}

在编译过程中使用 -std=c++11 选项来使用支持线程的最新标准

PS:
在我的电脑上使用 mingw 4.7.0 编译 boost 1.48 会出现错误(当尝试使用 boost::thread 时):
线程支持不可用:已使用 BOOST_DISABLE_THREADS 显式禁用它
所以我猜它在 g++ 4.7.0 中默认被禁用(在 g++ 4.6.2 中则没有)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文