Armadillo code cant compile in msys2 and netbeans - c++

I'm tring to compile a simple armadillo program by netbeans and msys2:
#include <cstdlib>
#include <armadillo>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
arma::Mat<double> A = arma::randu(4,4);
return 0;
}
I'm using netbeans 8.2, msys2 installed and configured with openblas and armadillo installed by pacman.
but I get this error:
cd 'D:\Users\Amir\Documents\NetBeansProjects\physics\CppApplication_2'
C:\msys64\usr\bin\make.exe -f Makefile CONF=Release
"/C/msys64/usr/bin/make.exe" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/d/Users/Amir/Documents/NetBeansProjects/physics/CppApplication_2'
"/C/msys64/usr/bin/make.exe" -f nbproject/Makefile-Release.mk dist/Release/MinGW-Windows/cppapplication_2.exe
make[2]: Entering directory '/d/Users/Amir/Documents/NetBeansProjects/physics/CppApplication_2'
mkdir -p build/Release/MinGW-Windows
rm -f "build/Release/MinGW-Windows/main.o.d"
g++ -c -O2 -std=c++11 -MMD -MP -MF "build/Release/MinGW-Windows/main.o.d" -o build/Release/MinGW-Windows/main.o main.cpp
In file included from C:/msys64/mingw64/include/armadillo:54,
from main.cpp:15:
C:/msys64/mingw64/include/armadillo_bits/compiler_setup.hpp:66:30: fatal error: C:/building/msys64/mingw64/include/hdf5.h: No such file or directory
#define ARMA_INCFILE_WRAP(x) <x>
^
compilation terminated.
make[2]: *** [nbproject/Makefile-Release.mk:68: build/Release/MinGW-Windows/main.o] Error 1
make[2]: Leaving directory '/d/Users/Amir/Documents/NetBeansProjects/physics/CppApplication_2'
make[1]: *** [nbproject/Makefile-Release.mk:59: .build-conf] Error 2
make[1]: Leaving directory '/d/Users/Amir/Documents/NetBeansProjects/physics/CppApplication_2'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2
BUILD FAILED (exit value 2, total time: 575ms)
I also installed hdf5 in msys2.
How can I get rid of this error?
thx.

it seems someone put this #define ARMA_HDF5_INCLUDE_DIR C:/building/msys64/mingw64/include/ into config.hpp in folder armadillo_bits. changing this to your usual include directory or setting it as nothing should fix the problem.

Related

Regex code stopped working for no reason

Here's the code that I'm trying to build and compile. I'm not sure what I did, but this code worked before (a couple of weeks ago).
#include <regex>
using namespace std;
int main(int argc, char** argv) {
regex txt_regex("[a-z]+\\.txt");
return 0;
}
Here's the error log from netbeans:
cd '/home/dev/Desktop/test'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/dev/Desktop/test'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/test
make[2]: Entering directory '/home/dev/Desktop/test'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
In file included from /usr/include/c++/5/regex:60:0,
from main.cpp:1:
/usr/include/c++/5/bits/regex_compiler.h: In member function ‘bool std::__detail::_AnyMatcher<_TraitsT, false, __icase, __collate>::operator()(std::__detail::_AnyMatcher<_TraitsT, false, __icase, __collate>::_CharT) const [with _TraitsT = std::__cxx11::regex_traits<char>; bool __icase = true; bool __collate = false; std::__detail::_AnyMatcher<_TraitsT, false, __icase, __collate>::_CharT = char]’:
/usr/include/c++/5/bits/regex_compiler.h:292:7: internal compiler error: Segmentation fault
operator()(_CharT __ch) const
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.
nbproject/Makefile-Debug.mk:66: recipe for target 'build/Debug/GNU-Linux/main.o' failed
make[2]: *** [build/Debug/GNU-Linux/main.o] Error 1
make[2]: Leaving directory '/home/dev/Desktop/test'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/dev/Desktop/test'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
What's going on?
The code works again after I updated my system:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

Netbeans C++ Compiler Error

Let me start by saying that I am a Windows 8 user on a HP laptop.
So I very recently started an online course in c++ with 'c++ institute'. As recommended by them, I downloaded the MinGW/MSYS package, JDK and NetbBeans IDE version 8.0.2.
I followed their installation instructions exactly (including updating the path directory by adding ";C:\MinGW\bin;C:\MinGW\MSYS\1.0\bin")
I am now on chapter 3 of the program and everything was going ok until I tried to compile the following code (see below)
/*
* File: hello.cpp
*
* Created on 19 May 2015, 18:26
*/
#include <cstdlib>
#include <iostream>
#include <stdio.h>
int main(void) {
int exp;
int pow = 1;
for(exp = 0; exp < 16; exp++) {
printf("2 to the power of %d is %d\n",exp,pow);
pow = pow*2;
}
return 0;
}
For some reason when I try to compile and run the program I get the following error messages
"/C/MinGW/MSYS/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/Philip/Desktop/C++ Course/Hello'
"/C/MinGW/MSYS/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/hello.exe
make.exe[2]: Entering directory `/c/Users/Philip/Desktop/C++ Course/Hello'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/hello.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/hello.o.d" -o build/Debug/MinGW-Windows/hello.o hello.cpp
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/hello build/Debug/MinGW-Windows/hello.o
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot open output file dist/Debug/MinGW-Windows/hello.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/hello.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/Philip/Desktop/C++ Course/Hello'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/Philip/Desktop/C++ Course/Hello'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 4s)
The code was copied and pasted directly from the course files and it seems to make sense to me. So can anybody tell me what I am doing wrong? Thanks in advance.
The relevant error message is
cannot open output file dist/Debug/MinGW-Windows/hello.exe: Permission denied
Which indicates you do not have write permission on the folder it's attempting to create hello.exe in. Make the dist/Debug/MinGW-Windows folder writable, and that error should be resolved.
https://netbeans.org/community/releases/80/cpp-setup-instructions.html#compilers_windows
Try by instructions given over here.

Using Netbeans with Cygwin and SDL, including SDL.h creates strange error

I've got Netbeans C/C++ set up, Cygwin installed, configured and running correctly. SDL was installed from the sources using the Cygwin terminal. I've confirmed that Cygwin, Netbeans and SDL are all running correctly, I can write and compile C++ projects just fine with Netbeans and Netbeans can see SDL without having to include any files or anything, it just works like the default libraries.
#include <cstdlib>
#include <sdl2/SDL.h>
using namespace std;
int main(int argc, char** argv) {
return 0;
}
That's the code I'm trying to compile, Netbeans doesn't highlight the include for sdl.h, but when I go to build I get this:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/Cally/Projects/Test'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/test.exe
make[2]: Entering directory '/home/Cally/Projects/Test'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f "build/Debug/Cygwin_4.x-Windows/main.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/Cygwin_4.x-Windows/main.o.d" -o build/Debug/Cygwin_4.x-Windows/main.o main.cpp
mkdir -p dist/Debug/Cygwin_4.x-Windows
g++ -o dist/Debug/Cygwin_4.x-Windows/test build/Debug/Cygwin_4.x-Windows/main.o
/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib/libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-1.7.30-1/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain'
/usr/src/debug/cygwin-1.7.30-1/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/Cygwin_4.x-Windows/test.exe' failed
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/test.exe] Error 1
make[2]: Leaving directory '/home/Cally/Projects/Test'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/Cally/Projects/Test'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
The build is successful when I don't include SDL. Anybody know what I'm doing wrong?
The error message looks really evil - but it just tells you it can't find a WinMain.
This is a known issue with SDL. Please add those libraries to your linker (order is mandatory!):
mingw32
SDLmain
SDL
You can either add -lmingw32 -lSDLmain -lSDL to linker options or add them through the library menu of linker config.
It's possible you need SDL_mixer too - if so, just add it last.
Please see also: http://content.gpwiki.org/index.php/SDL%3aTutorials%3aSetup
As a "dirty workaround" you can do this: undefine main.
SDL redefines main() as a macro with some additional stuff. You can verify this by egl. Ctrl + click on main / go to declaration / definition or check if it's formatted as makro.
#include <cstdlib>
#include <sdl2/SDL.h>
using namespace std;
/*
* If 'main' is defined we clear that definition
* to get our default 'main' function back.
*/
#ifdef main
# undef main
#endif /* main */
int main(int argc, char** argv) {
return 0;
}
Please see source of SDL_main.h (line 103+).

Netbeans and C++ installation

i have a litle problem using Netbeans 7.4 and Cygwin 4.x for compiling my C++ programms. I've done everything as in netbeans tutorial. I've installed gcc, gdb, g++ and make compilers. Everything is setup properly in Netbeans properties, every path. But i still get the same problem, i don't know what is this problem. I'm trying to compile Hello sample from Netbeans. Please help me. Here is the error log:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/Dragosh/Documents/NetBeansProjects/Welcome_2'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/welcome_2.exe
make[2]: Entering directory '/cygdrive/c/Users/Dragosh/Documents/NetBeansProjects/Welcome_2'
mkdir -p build/Debug/Cygwin_4.x-Windows
g++ -c -g -o build/Debug/Cygwin_4.x-Windows/welcome.o welcome.cc
In file included from /usr/include/sys/reent.h:14:0,
from /usr/include/wchar.h:6,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/cwchar:44,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/bits/postypes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/iosfwd:40,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/ios:38,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/iostream:39,
from welcome.cc:31:
/usr/include/sys/_types.h:72:20: fatal error: stddef.h: No such file or directory
#include <stddef.h>
^
compilation terminated.
nbproject/Makefile-Debug.mk:66: recipe for target 'build/Debug/Cygwin_4.x-Windows/welcome.o' failed
make[2]: *** [build/Debug/Cygwin_4.x-Windows/welcome.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/Dragosh/Documents/NetBeansProjects/Welcome_2'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/Dragosh/Documents/NetBeansProjects/Welcome_2'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 467ms)
Got this issue with cygwin too, after last update to 2.830 (see setup.exe version). I am using 64 bit version. To verify that we have the same issue, try manualy compiling something supersimple with g++ usgin cygwin terminal.
I checked with:
$ echo -e "#include <iostream>\n int main() { return 0; }" | g++ -xc++ -
And got:
In file included from /usr/include/sys/reent.h:14:0,
from /usr/include/wchar.h:6,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/cwchar:44,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/bits/postypes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/iosfwd:40,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/ios:38,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/include/c++/iostream:39,
from <stdin>:1:
/usr/include/sys/_types.h:72:20: fatal error: stddef.h: No such file or directory
#include <stddef.h>
^
compilation terminated.
I noticed that there are two folders of gcc here
C:\cygwin\lib\gcc\x86_64-pc-cygwin\4.8.1
C:\cygwin\lib\gcc\x86_64-pc-cygwin\4.8.2
and g++ --version gives 4.8.2
Running Cygwin's latest Setup.exe and looking for installed packets showed that versions mismatch for gcc-core and gcc-g++ :
gcc-core = 4.8.2-1
gcc-c++ = 4.8.1-3
I downgraded gcc-core to 4.8.1-3 and fixed the issue.

SDL MinGW Netbeans. <SDL/SDL.h> no such file or directory

PROBLEM SOLVED
Go to bottom to see the solution.
Hello everybody i've been googling' looooong time and I didn't find anythinig, so, here we go:
I have this setup:
Compiler: MinGW IDE: Netbeans Library: SDL Language:
C++
Okey, so, i have included this folder: "C:/SDL_1.2.15/include"
And Linked those libraries in this order:
-lmingw32
-lSDL_main
-lSDL
Then if I use a normal program without the #include "SDL/SDL.h" then compiles okeey.
So if i include the SDL header file the IDE gives me greenlight to compile an then, i get this output:
"C:/WinAVR-20090313/utils/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Users/pablo/Documents/NetBeansProjects/SDL_Test'
"C:/WinAVR-20090313/utils/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/sdl_test.exe
make[2]: Entering directory `C:/Users/pablo/Documents/NetBeansProjects/SDL_Test'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++.exe -c -g -Wall -I/C/MinGW/include -I/C/SDL-1.2.15/include -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
make[2]: Leaving directory `C:/Users/pablo/Documents/NetBeansProjects/SDL_Test'
make[1]: Leaving directory `C:/Users/pablo/Documents/NetBeansProjects/SDL_Test'
main.cpp:11:21: error fatal: SDL/SDL.h: No such file or directory
compilaci�n terminada.
make[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
So! Here is the source code of my application, it only has a 'main.cpp' file:
/*
* File: main.cpp
* Author: pablo
*
* Created on 1 de septiembre de 2013, 23:20
*/
#include <cstdlib>
#include <windows.h>
#include <SDL/SDL.h>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
return 0;
}
I've found new issues; When I remove the #include (comment //) then the console throws me this errors instead the 'no such file or directory':
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lSDLmain
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lSDL.dll
When I compile without #include using Cygwin compiler, the project builds correctly.
Found another issue:
make[2]: *** No rule to make target `/C/SDL-1.2.15/lib/libSDLmain.a', needed by `dist/Debug/MinGW-Windows/sdl_test.exe'. Stop.
this happens when I add the full path to the SDL libraries instead of -lSDL.dll and -lSDL_main
SOLUTION:
The problem solves coping c:/SDL-1.15/include/SDL/ folder to c:/MinGW/include/ directory, and libraries from lib on c:/SDL-1.15/lib/SDL to MinGW/lib
You have to add the headers separately.
It's not enough to do the include, you have to do multiple things to add a thing like SDL in your project.