Simple netbeans C++ project doesn't compile - c++

I installed Netbeans and as C++ compiler I installed cygwin. I made a simple project to test out my installation, this is the code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "test";
return 0;
}
This is the error message that it gives: http://pastebin.com/jRRh7MPi
I hope you guys can help me out.

You need to either explicitly link to C++ standard library, or compile using g++ instead of gcc.

Related

Matplotlib wrapper for c++

I'm trying to get Matplotlib wrapper to work on wxDevC++
The code
#include <cstdlib>
#include <iostream>
#include "matplotlib-cpp/matplotlibcpp.h"
#include <vector>
namespace plt=matplotlibcpp;
using namespace std;
int main(int argc, char *argv[])
{
std::vector<double> y={1,3,2,4};
plt::plot(y);
plt::savefig("minimal.pdf");
cout << "Press the enter key to continue ...";
cin.get();
return EXIT_SUCCESS;
}
I use Win 7, I have python 27 and Python 38. It keeps telling me that there is no Python.h file. I've no idea how to fix this.
You have to set the include path for Pathon.h in your build configuration and you have to use at least C++11.
You can set the C++ standard in GCC and compatible compilers with the compiler option -std=c++11 or in older versions with -std=c++0x. For the GNU variants you can use -std=gnu++11 resp. -std=gnu++0x.

Using DLLs wrapping Windows PackageManager in MinGW

In an attempt to incorporate a windows platform feature into an otherwise crossplatform application, I've made a one-function VC++ DLL in visual studio that uses Windows.Management.Deployment.PackageManager to get some details on all installed windows store apps.
The function works fine as a standalone application, and I can successfully build the DLL with MSVC that links properly with my MinGW main application (I can happily return primitive data from the dll, etc) - but any attempt to execute a function from the dll containing code relating to PackageManager crashes my application in runtime with the unhelpful code -529697949.
Here's some minimal code blocks that replicate:
main.cpp in the main application:
#include <QCoreApplication>
#include "mylib/WindowsAppsLib.h"
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
auto hi = (Helpers::sayHi());
qDebug() << (hi);
return a.exec();
}
dll header:
#pragma once
#define WINDOWSAPPSLIB_API __declspec(dllexport)
namespace Helpers
{
extern "C" WINDOWSAPPSLIB_API const char* sayHi();
}
dll source:
#include "stdafx.h"
#include <sddl.h>
#include <collection.h>
#include "WindowsAppsLib.h"
#include <windows.h>
#using <Windows.winmd>
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace std;
const char* Helpers::sayHi()
{
auto packageManager = ref new Windows::Management::Deployment::PackageManager();
auto packages = packageManager->FindPackages();
return "Hi!";
}
Without the two lines relating to packagemanger, the program runs fine and prints "Hi!". When included, the program crashes with code -529697949 as soon as sayHi() is called. The two lines in themselves have their dependencies available and don't cause exceptions.
Any clues on how I might proceed to investigate this? Nothing I've been able to get out of this system is getting me closer to identifying the problem. Is this the sensible way to access Windows.Management.Deployment.PackageManager from within a plain C++ MinGW application to begin with?

What's wrong with std::strings

Hi I am new to C++ and Code::Block
I am trying to make a simple code to test it, using strings.
when I compile the code there is no problem, but when I try to debug it, Code::Block gives me the following warning:
Cannot open file:
File:../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c
Info: "Multiple information windows with the same message have been
supressed."
Image of the error FYI:
Part of the code that gives me an error.
inside main function
#include <iostream>
#include <string>
int main ()
{
std::mystring("What's wrong with strings");
return 0;
}
I realise that this error only occurs when I try to debug a string or a file containing a string.
Any help would be appreciated.
some other information that might help:
Code::Block 16.01
Compiler MinGW gcc4.9.2
Windows 7 Professional 32 bits SP1
First of all, to use strings you must include the file header string. And the name of the type string is..std::string, not std::mystring.
#include <string>
int main(int argc, char** argv)
{
std::string mystring("Nothing's wrong with strings");
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
string mystring = "Whats wrong with my string";
return 0;
}
If you write it in the following way, it should work.
It's safer to define strings like I showed it. It will be also easier for you if you add using namespace std in the beginning of every program if you are new to C++.

GCC iostream fstream error in Ubuntu 13.10

I am using Ubuntu 13.10. I am getting some errors for the following code.
#include <stdlib.h>
#include <stdio.h>
#include <fstream.h>
int main(int argc, char *argv[])
{
error.set_program_name(argv[0]);
if ( argc != 2 )
{
// printf(argv[0] + " usage: fifo_client [string] \n");
/// cout << argv[0] << " usage: fifo_client [string]" << endl;
exit(EXIT_FAILURE);
}
ofstream out(fifo_file);
if(out)
out << argv[1] << endl;
return(EXIT_SUCCESS);
}
If I run the above program a.c using command
gcc a.c -o a
a.c:1:20: fatal error: iostream: No such file or directory
#include <iostream>
^
compilation terminated.
I don't know whats the problem.
Use g++ instead of gcc. gcc could compile a c++ file if it had the right extension (.cpp for instance) or with the right arguments (-x c++) but adding the arguments needed to link with the C++ libraries is far too complex to avoid the simple solution.
The problem is that you're mixing C & C++ code and compiling it using GCC.
try
#include <fstream>
using namespace std;
instead of #include <fstream.h>
anyway your source code is not full to make correct suggestion.
I ran your code in my compiler and got following error :-
test2.c:3:21: fatal error: fstream.h: No such file or directory
#include <fstream.h>
^
compilation terminated.
so i think your question has typo.
It is because you are mixing c and c++ code, fstream is part of c++. try to run by g++.

MinGW portability

I'm completely new to C++, but I have created a minor program, looking to port the program to other computers, but when I "install" the program I get this error...-static-libgcc -static-libstdc++ missing, is there a file I should be including in the program itself, or is this a library I have to install on each computer? The computers that I expect to run the program will be windows xp. Source code of the file is as follows:
#include <stdlib.h>
#include <windows.h>
#include <direct.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, const char *argv[])
{
_chdir("C:\\Program Files\\NCHSoftware\\Talk\\");
string number = "start talk.exe -dial " + std::string(argv[1]+4);
system(number.c_str());
exit;
return 0;
}
They are shared lib's that would need to be on the host computer.
To learn how to compile a static version;
See here: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
Read the "-static-libgcc" & "-static-libstdc++" sections.