Eclipse Kepler: #include "boost/filesystem.hpp" breaking debugging? - c++

I have a fresh install of Eclipse Kepler on Windows 7 x64. My first "Hello world" worked great, including setting breakpoints and walking through code in debug mode. My second program links to Boost. I can set the breakpoints, build 'Debug' without errors, and run Debug, but unlike my Hello World, it blows through my breakpoints. The console window appears to flicker "Info: Nothing to build for..." and then clears. None of my std::cout calls appear.
With a little debugging I found that commenting out "filesystem.hpp" (below) enables the debugging, but of course I need it. I'm new to Eclipse. What would cause this behavior?
#include "boost/filesystem.hpp" <--- removing this enables debugging
#include "boost/regex.hpp"
#include <iostream>
int main()
{
std::cout << "Start search" << std::endl;
:
:

Look in the build output/problems views.
Most likely, you don't link to the required lib(s) for Boost Filesystem (-lboost_system -lboost_filesystem).
In effect this just means that no executable is built, and obviously therefore cannot be started.

Related

String variables don't work in Eclipse CDT

When I use string variables in Eclipse CDT (MinGW compiler) and I run the program, it doesn't show me anything. Here's my code:
#include <iostream>
using namespace std;
int main() {
string hw = "Hello, world!";
cout << hw << endl;
return 0;
}
So that doesn't show anything, but when I just do cout << "Hello, world!" << endl; it does work.
I also tried including <string>, <string.h>, "string" and "string.h" but still no success. The same code does work in VC++ and Codeblocks though.
I can reproduce this problem on my machine. The output does not appear. But it is not an output problem, but actually two problems before you get to main:
The program is failing to launch. If you try double-clicking on it in Windows Explorer, you will get an error message like this:
The program can't start because libgcc_s_dw2-1.dll is missing from
your computer. Try reinstalling the program to fix this problem.
Screenshot of above:
When launched from within Eclipse, this error message is silently swallowed, so how are you supposed to know!
Solutions/Workarounds
You need to get the environment correctly set up to launch the MinGW program because its DLLs are not installed on Windows PATH or other standard places DLLs are searched for.
Add C:\MinGW\bin to your PATH
Launch Eclipse from within a MinGW shell (has basically same effect as 1)
Run the program in debug mode, this causes the program to be launched as a child of GCC and that sets up
Other options (not tried by me) may include statically linking the offending library, see The program can't start because libgcc_s_dw2-1.dll is missing
File a CDT bug about the error message being hidden.
Extra info
If your program compiles, as I am sure it does based on your comments, changing the includes is probably irrelevant.
By adding an infinite loop around the couts I could immediately identify something more than simply an output not being shown was going on. Try the same thing on your machine, and also try running the program from within MinGW shell and from outside it.

No output in c++-program if object is instantiated using Eclipse

I got an issue after installing Eclipse Kepler on my Windows 7 32bit machine. I installed the CDT and the MinGW-compiler. I configured the installation by adding MinGW to the PATH and tested my configuration with a "Hello world"-program, which worked.
The strange thing is, that if I instantiate an object, nothing is outputted. It doesn't matter if it's a std::string or a custom made class. If I instantiate it, nothing is outputted, even if it should be outputted before the instantiation. The exact same code works fine, if I compile it with cygwin gcc from command line. If I change the toolchain to cygwin gcc nothing changes (I've rebuild the program with "build all").
There is no error displayed and no problem listed.
Here's the minimal working example:
#include <iostream>
#include <string>
using namespace std;
class SayWorld{
public:
SayWorld(){
cout << "World!" << endl;
}
};
int main() {
//Only gets outputted, if the lines, that don't work are commented out:
cout << "Hello ";
// Works:
cout << "World!" << endl;
// Doesn't work:
// SayWorld sw;
// Also doesn't work:
// string str("World!");
// cout << str << endl;
return 0;
}
Edit 2:
I narrowed the error to MinGW, as this picture of a Cygwin-Bash-Terminal demonstrates. (The file was not changed beetween the to g++ calls and contains the example above)
Edit 1 (Legacy)
Toolchain-picture:
-picture removed- (don't think it was necessary)
After reinstalling eclipse and MinGW again, step-by-step following this video tutorial:
http://www.youtube.com/watch?v=77xZOT3xer4
and having the same problem afterwards, I stumbled uppon this post in the eclipse forum:
http://www.eclipse.org/forums/index.php/u/104305/
which has brought me to this solution:
Right-click Project -> Properties -> Run/Debug Settings
Choose executable and hit the "New"-button.
Go to the Environment-Tab and create a new variable named PATH with the value: "C:\MinGW\bin".
As I am no expert, I can't explain to you why it works, but it worked for me. If someone knows, how to do this better or wholly avoid this problem, I'd be glad to listen.
This entry was definitively in my Windows-PATH...
PS.: The problem seems also to be known here:
unable to see the output of c++ program in the console

Codeblocks outputs broken executable

I have downloaded plenty of different versions of code blocks, and none of them compiles quite right. My hello world runs within code blocks just fine. However, when I run the executable outside of codeblocks, it says "Hello.exe has stopped working". There isn't anything wrong with my code (I don't think.) and my mingw compiles fine outside of codeblocks. What does codeblocks do to my executable? Is there some option to fix this? I am on windows 7 64 bit, and my current code blocks version is 10.05. My program:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
cin.ignore();
return 0;
}
I solved the problem. I had a broken compiler (or something like that). My suggestion for other people with this problem is to experiment with different versions of the minGW compiler. Also, change the version of code blocks you are using, or even uninstall everything and restart. The problem with mine was I downloaded a bad compiler. [The truth is, codeblocks isn't the best ide.]

Standard library not resolved in Eclipse Juno

I am building a Makefile project in Eclipse Juno, and I have it set up so it compiles and debugs (it's using CMake, so I'm not using the internal tools). However, Eclipse obviously hasn't been informed of the right headers, as in the following code:
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello world << endl;
return 0;
}
the include "iostream" and symbols "std", "cout" and "endl" are all unresolved.
How should I make Eclipse aware of these so it will stop underlining everything in red and spamming with errors?
This can be resolved by specifying the following environmental variables in Project->Properties->C++ Build->Environment.
LANG=en_US
LC_ALL=en_US
Apparently they are needed for the auto-discovery tools to work out where the includes live.
Answer gleaned from this Eclipse forum thread.

Xcode 3.2.1 and C++ string fails!

In Xcode 3.2.1 on Mac OS X Snow Leopard, I open a project under:
Command Line Tool of type C++ stdc++.
I have the following simple code:
#include <iostream>
#include <string>
using namespace std;
int main(){
string myvar;
cout << "Enter something: " << endl;
cin >> myvar;
cout << endl << myvar << endl;
return 0;
}
The program compiles fine, and prompts me to "Enter Something". When I type in something, and then press enter, I get the following error:
myproject(766) malloc: *** error for object 0x1000041c0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program received signal: “SIGABRT”.
sharedlibrary apply-load-rules all
(gdb)
When compiling on an earlier version of Xcode (3.1.2) on a different computer (opened the project with the 'command line utility' option, which does not exist in 3.2.1), the code runs with NO PROBLEM.
Does anybody know what's going on?
Thanks,
Yuval
As far as I can tell, I'm not experiencing this issue in Release mode for x86_64. But I am seeing the issue in Debug x86_64. If I follow the directions given by Howard in this post, I'm able to get it running in debug mode:
Project -> Edit Active Target ...
Click Build tab
Search for "preprocessor"
Delete _GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1
Build and run, you'll notice it works. Another interesting observation is that using __gnu_debug::string (from the <debug/string> header) alone does not trigger the error.
EDIT: from the horses mouth (known issues in XCode 3.2.1)
The default gcc 4.2 compiler is not compatible with the Standard C++ Library Debug Mode. C++ programs compiled with Xcode 3.2 may not work in the Debug configuration. To fix this, set the Compiler Version to 4.0, or edit the Debug configuration’s Preprocessor Macros and remove the entries:
_GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1
You can do this for all projects by navigating to /Developer/Library/Xcode/Project Templates/Application/Command Line Tool/C++ Tool/C++Tool.xcodeproj/ and editing project.pbxproj and deleting the lines around line 138:
"_GLIBCXX_DEBUG=1",
"_GLIBCXX_DEBUG_PEDANTIC=1",
An easier way of accomplishing the same thing: paste these lines at the very beginning of your program (before any #include statements):
#define _GLIBCXX_FULLY_DYNAMIC_STRING 1
#undef _GLIBCXX_DEBUG
#undef _GLIBCXX_DEBUG_PEDANTIC
Obviously, this will only affect the current project.