netbeans c++程序无法运行

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了netbeans c++程序无法运行相关的知识,希望对你有一定的参考价值。

系统:win7,工具集合:cygwin。Cygwin和NetBeans都是新安装的,安装Cygwin包括gcc,g++,gdb,make,Cygwin已在系统变量中添加了(;E:\cygwin),NetBeans里已在工具-》选项 中添加了cygwin,(从基目录到调试器命令,除了Fortran都添了)

然后我编写程序:
#include<iostream>
using namespace std;

int main()

printf("123\n");


编译成功,但找不到包含文件<iostream>,无法解析标示符std,无法解析标示符printf 运行时不出结果,不出现控制台,右下角一直有一个进度条。以前这个代码没有问题,结果123显示在控制台上

求解
Netbeans 6.7 cpp

要配置头文件路径,
解决办法如下:
工具 -》 选项 -》 C/C++ -》 C++编译器 -》 添加 -》/usr/include/c++/4.2.4(你的可能不是4.2.4)
参考技术A 如果找不到头文件怎么可能编译成功呢?

为 C++/Boost 库设置环境(netbeans 或 eclipse)

【中文标题】为 C++/Boost 库设置环境(netbeans 或 eclipse)【英文标题】:Setting up environment for C++/Boost libs (netbeans or eclipse) 【发布时间】:2011-05-15 00:55:49 【问题描述】:

我现在已经学习了很多教程,但我无法正确掌握这个基本的、基本的东西。 我开始使用 C++ 并从标准介绍内容(两本书之后)继续前进,并且我正在研究“超越 C++ 标准库 ~ Boost 简介”,但我似乎无法获得 Netbeans 或 Eclipse编译和运行我的 boost 项目。

我看过How to configure Boost with Netbeans 6.9 on Ubuntu http://www.fischerlaender.net/development/using-boost-c-libraries-with-gcc-g-under-windows 和其他一些人,但我似乎无法正确理解。 在 Netbeans (我的偏好)中,我已经指定了额外的包含目录,并且 netbeans 识别到它在包含来自 boost/* 的任何内容时提供自动完成的程度,例如 #include 很好,但是当我尝试编译它时我明白了:

mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++.exe    -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
main.cpp:7:27: fatal error: boost/regex.hpp: No such file or directory
compilation terminated.
make[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `/c/Users/Courtney/Documents/Projects/Desktop/HelloBoost'
make[1]: Leaving directory `/c/Users/Courtney/Documents/Projects/Desktop/HelloBoost'

但我不明白为什么找不到文件...非常感谢任何帮助。 更新 在 Properties->C++ Compiler 下设置 include 目录,并选择 32 位作为架构。编译错误改为:

"/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/Users/Courtney/Documents/Projects/Desktop/HelloBoost'
"/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/helloboost.exe
make[2]: Entering directory `/c/Users/Courtney/Documents/Projects/Desktop/HelloBoost'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++.exe -m32   -c -g -I/C/Program\ Files\ \(x86\)/boost/boost_1_46_1 -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
mkdir -p dist/Debug/MinGW-Windows
g++.exe -m32    -o dist/Debug/MinGW-Windows/helloboost build/Debug/MinGW-Windows/main.o  
build/Debug/MinGW-Windows/main.o: In function `cpp_regex_traits_char_layer':
c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:366: undefined reference to `boost::re_detail::cpp_regex_traits_char_layer<char>::init()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/regex_raw_buffer.hpp:131: undefined reference to `boost::re_detail::raw_storage::resize(unsigned int)'
build/Debug/MinGW-Windows/main.o: In function `save_state_init':
c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/perl_matcher_non_recursive.hpp:107: undefined reference to `boost::re_detail::get_mem_block()'
build/Debug/MinGW-Windows/main.o: In function `~save_state_init':
c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/perl_matcher_non_recursive.hpp:115: undefined reference to `boost::re_detail::put_mem_block(void*)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/perl_matcher_common.hpp:206: undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/perl_matcher_non_recursive.hpp:1117: undefined reference to `boost::re_detail::put_mem_block(void*)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/pattern_except.hpp:75: undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_parser.hpp:218: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_parser.hpp:219: undefined reference to `boost::regex_error::raise() const'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_parser.hpp:218: undefined reference to `boost::regex_error::~regex_error()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_parser.hpp:218: undefined reference to `boost::regex_error::~regex_error()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:795: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:796: undefined reference to `boost::regex_error::raise() const'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:795: undefined reference to `boost::regex_error::~regex_error()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:877: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:878: undefined reference to `boost::regex_error::raise() const'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:877: undefined reference to `boost::regex_error::~regex_error()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:795: undefined reference to `boost::regex_error::~regex_error()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:877: undefined reference to `boost::regex_error::~regex_error()'
make[2]: Leaving directory `/c/Users/Courtney/Documents/Projects/Desktop/HelloBoost'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:942: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
make[1]: Leaving directory `/c/Users/Courtney/Documents/Projects/Desktop/HelloBoost'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:943: undefined reference to `boost::regex_error::raise() const'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:942: undefined reference to `boost::regex_error::~regex_error()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:942: undefined reference to `boost::regex_error::~regex_error()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:1133: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:1134: undefined reference to `boost::regex_error::raise() const'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:1133: undefined reference to `boost::regex_error::~regex_error()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:1133: undefined reference to `boost::regex_error::~regex_error()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/perl_matcher_non_recursive.hpp:213: undefined reference to `boost::re_detail::get_mem_block()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:442: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:444: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:320: undefined reference to `boost::re_detail::raw_storage::insert(unsigned int, unsigned int)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:625: undefined reference to `boost::re_detail::lookup_default_collate_name(std::string const&)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:667: undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:682: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:1051: undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:1051: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
build/Debug/MinGW-Windows/main.o:c:/Program Files (x86)/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:1051: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/MinGW-Windows/helloboost.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 31s)

【问题讨论】:

【参考方案1】:
g++.exe    -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp

该编译命令没有必要的-I 开关。似乎包含目录设置在错误的位置。也许它只是设置为自动完成,而不是编译?

【讨论】:

在哪里添加包含目录?我在 Properties -> C++ , Linker 和 Tools->Libs->C++ 下尝试过 它应该是与编译器相关的东西,而不是链接器。我真的很抱歉我不使用 NetBeans。这是我发现的内容:要提供必要的包含目录,请右键单击项目图标并选择属性。从类别框中,选择 C/C++、C 编译器、通用节点。单击包含目录附近的按钮。将必要的路径添加到包含目录。看看这对你有没有帮助。 没关系,谢谢回复。我以前做过,但没有用。又试了一次还是不行。如果您不介意我问,您使用什么 IDE,或者您会推荐哪一个用于 boost。 我使用了 Eclipse CDT。然后我切换到 Microsoft Visual C++ Express。现在我在使用 Qt Creator。在 Windows 上,使用 MS Visual C++(Express 与否)都不会出错。 再次感谢您的回复。我已经切换到 Ubuntu,这将使我的生活更轻松。使用 Win7 进行双启动...安装了 boost 和 netbeans 和 presto,已经在使用一些库。再次感谢

以上是关于netbeans c++程序无法运行的主要内容,如果未能解决你的问题,请参考以下文章

NetBeans 无法在 Maven Web 应用程序上运行 package.json

Netbeans C++ 错误:193

我无法让 Netbeans C++ 工作,我做错了啥?

运行 C++ 应用程序时摆脱黑色控制台窗口

Netbeans Cordova PushPlugin 无法在 iOS 上运行

无法在命令行上将 Netbeans 生成的 .java 文件编译成 .class