I'm a fresh c++ user in Windows 8 system. I have installed MinGW and setup the environment variables. I create the simplest hellow world code as below
#include<iostream>
#include<vector>
using namespace std;
int main(int argc, char **argv)
{
cout<<"hello world"<<endl;
return 0;
}
It works well at the first time, but when I do some small modification, for example delete "hello", and then build and run the project again. I found that the program will keep running without end. The command line keeps showing:
Current working directory: C:\Users\cr\Documents\project\helloworld\Debug
Running program: le_exec.exe ./helloworld
If I try to build it again, it shows
make.exe[1]: Entering directory 'C:/Users/cr/Documents/project/helloworld'
C:/Users/cr/MinGW/bin/g++.exe -c "C:/Users/cr/Documents/project/helloworld/main.cpp" -g -O0 -Wall -o ./Debug/main.cpp.o -I. -I.
C:/Users/cr/MinGW/bin/g++.exe -o ./Debug/helloworld #"helloworld.txt" -L.
c:/users/cr/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot open output file ./Debug/helloworld.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
make.exe[1]: *** [Debug/helloworld] Error 1
helloworld.mk:78: recipe for target 'Debug/helloworld' failed
make.exe[1]: Leaving directory 'C:/Users/cr/Documents/project/helloworld'
make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
====1 errors, 0 warnings====
I could not even delete the executable file "helloworld.exe" because it is using in 'System' until I restart the computer.
Update:
I can compile it in the command line:
C:/Users/cr/Documents/project/helloworld>g++ main.cpp -o test.exe
C:/Users/cr/Documents/project/helloworld>test.exe
It will then keep running until I close the command line window. If I open a new command line window and compile the file again. There is no problem.
Update2:
Problem also happens when I compile the cpp file the second time even if the file has not been edited.
C:/Users/cr/Documents/project/helloworld>g++ main.cpp -o test.exe
C:/Users/cr/Documents/project/helloworld>test.exe
hello world
C:/Users/cr/Documents/project/helloworld>g++ main.cpp -o test2.exe
C:/Users/cr/Documents/project/helloworld>test2.exe
It keeps running here.
Thanks all, I struggled with it for a whole day. The problem is anti-virus software...... I set it inactive and all things do well...
I don't want to point out what this software is, but just want to give out a reminder for this problem....
Related
I have included vsprintf in my project. However, when I compile it I receive the following error.
/opt/xgcc/decstation-ultrix/bin/xgcc -DIN_USER_MODE -c -I../userprog -I../threads -G 0 -Wall -O2 -DCHANGED -c vsprintf.c
vsprintf.c:12: stdarg.h: No such file or directory
make[1]: *** [vsprintf.o] Error 1
rm add.o
make[1]: Leaving directory `/home/banana/se31/code/test'
make: *** [all] Error 2
Line 12 of vsprintf contains the following:
#include <stdarg.h>
I verified that stdarg.h is properly installed in my system using the following short programs.
//test.c and test.cpp
#include <stdarg.h>
int main(void)
{
return 0;
}
When I run gcc test.c or gcc test.cpp I receive no errors which implies that my vsprint.c and gcc is properly installed.
I have gone through similar questions in stackoverflow but have not got a solution yet. I am using Ubuntu 32 bit as my Operating System. Could someone guide me on how I can resolve this issue?
As hvd
pointed out. I was checking for stdarg.h in the wrong place. To fix it, stdarg.h had to be added to my project. From there, the cross compiler (xgcc) was able to compile the program.
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+).
I'm a total c++ Newbie.
I'm trying to build windows aplications with Wx-Widgets under Net Beans.
So far so good. I have instaled everything, configured, build wx-widgets and attached it to the new project - with help of a good man here: Can't make wx-widget work with net-beans.
Now I try to build my first app:
#include <wx/string.h>
int main(int argc, char **argv)
{
wxPuts(wxT("A wxWidgets console application"));
}
and this is what I get:
I'm not sure if this is readable so I paste the errors:
g++ `C:\WXWIN\wx-config --cxxflags` -c -g -I../../../WXWIN/include `C:\WXWIN\wx-config --cxxflags` -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
/bin/sh.exe: C:WXWINwx-config: command not found
/bin/sh.exe: C:WXWINwx-config: command not found
In file included from ../../../WXWIN/include/wx/defs.h:21:0,
from ../../../WXWIN/include/wx/string.h:25,
from main.cpp:1:
../../../WXWIN/include/wx/platform.h:196:22: fatal error: wx/setup.h: 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/xampp/htdocs/WxWwigets_tutorial'
make[1]: Leaving directory `/c/xampp/htdocs/WxWwigets_tutorial'
BUILD FAILED (exit value 2, total time: 859ms)
Please notice that I have set everything in linker and compiler like ordered: http://wiki.wxwidgets.org/Compiling_using_Netbeans
The error is right in front of you: "command not found". If you use /bin/sh, you must use Unix style paths, e.g. C:/WXWIN/wx-config instead of DOS paths with the backslashes.
I seriously advise you to get familiar with the environment you're using instead of just following the Wiki instructions without understanding them, otherwise your problems won't be over any time soon.
I have some problems linking to GLFW in Netbeans, I have followed the instructions here:
http://forums.netbeans.org/topic51143.html
I have installed Cygwin and MinGW on my computer, I had since earlier an installation of Cygwin, which I tried to use to compile a GLFW program, but I got the same error, so I decided to try MinGW, as per the instructions, still the same problem.
Also, for some reason I can't use msys make.exe as make command, even for compiling a C++ hello world, I have to use the one in Cygwin instead. I have set up windows Path variable to include the locations of both the msys bin directories.
"1) What must be installed (dlls, etc)?
glfw.dll
libgcc_s_dw2-1.dll
libstdc++-6.dll"
I am not sure what this means, does installed in this instance mean that System32/SysWOW64 should contain those mentioned .dlls?
My output for this program (using linker properties as specified here :
http://forums.netbeans.org/topic51143.html)
#include <cstdlib>
#include <stdio.h>
#include <GL/glfw.h>
using namespace std;
int main(int argc, char** argv) {
if (!glfwInit())
return -1;
return 0;
}
Yields:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory /cygdrive/c/Users/sysdba/Documents/NetBeansProjects/GLFW'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_QT-Windows/glfw.exe
make[2]: Entering directory/cygdrive/c/Users/sysdba/Documents/NetBeansProjects/GLFW'
mkdir -p build/Debug/MinGW_QT-Windows
rm -f build/Debug/MinGW_QT-Windows/main.o.d
g++.exe -lglfwdll -DGLFW_DLL -c -g -Wall -I../../../Downloads/glfw-2.7.7.bin.WIN64/glfw-2.7.7.bin.WIN64/lib-mingw -MMD -MP -MF build/Debug/MinGW_QT-Windows/main.o.d -o build/Debug/MinGW_QT-Windows/main.o main.cpp
g++: -lglfwdll: linker input file unused because linking not done
mkdir -p dist/Debug/MinGW_QT-Windows
g++.exe -lglfwdll -DGLFW_DLL -o dist/Debug/MinGW_QT-Windows/glfw build/Debug/MinGW_QT-Windows/main.o -L../../../../../MinGW/lib -lglfw -lglu32 -lopengl32 -lglfwdll
nbproject/Makefile-Debug.mk:62: recipe for target dist/Debug/MinGW_QT-Windows/glfw.exe' failed
make[2]: Leaving directory/cygdrive/c/Users/sysdba/Documents/NetBeansProjects/GLFW'
nbproject/Makefile-Debug.mk:59: recipe for target .build-conf' failed
make[1]: Leaving directory/cygdrive/c/Users/sysdba/Documents/NetBeansProjects/GLFW'
nbproject/Makefile-impl.mk:39: recipe for target .build-impl' failed
build/Debug/MinGW_QT-Windows/main.o: In functionmain':
/cygdrive/c/Users/sysdba/Documents/NetBeansProjects/GLFW/main.cpp:20: undefined reference to `_imp_glfwInit#0'
collect2: ld returned 1 exit status
make[2]: * [dist/Debug/MinGW_QT-Windows/glfw.exe] Error 1
Any idea of what the problem could be? Could it be related to the fact that I am not using the msys make.exe as make command?
I fixed my MinGW install, so I could use the make.exe in the MinGW msys, instead of the cygwin mysys, did not help.
Not much of an answer, but it seems to be a problem with GLFW somewhere, could not get it to work. I switched to freeglut, Worked like a charm, without any hassle.
Im running into big trouble with my compiler Dev-C++, every time i compile any project, whether it is 1 im working on, or a completely fresh 1 I get the same error every single time, I have been on the bloodshed forums and IRC channel but Im not getting anywhere with it... at the moment and every project I try to compile gives the same error...
C:\Dev-Cpp\MY_Project\Makefile.win [Build Error] [main.o] Error 1
Compiler log
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\MY_Project\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\MY_Project\Makefile.win" all
g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -pg -g3
The system cannot find the path specified.
make.exe: *** [main.o] Error 1
Execution terminated
What is your OS? I think Bloodshed version of the program have some problems with Win8. However you can download Orwell version. It runs smoothly.
Have you looked at this thread? Specifically the first post on this page.