Compiling through command prompt problem
Hi, I am using gcc compiler to compile the program and build an exe
I used this command to compile
gcc program.cpp -g -o program (generates program.exe and runs fine)
But, if i write the same thing in system("gcc program.cpp -g -o program"); programmatically, then the exe is generated but, while running it I get a prompt saying "the exe is not compatible...... make see whether you need 32 bit or 62 bit"
I'm using dev c++ for the program! any solutions??
I used this command to compile
gcc program.cpp -g -o program (generates program.exe and runs fine)
But, if i write the same thing in system("gcc program.cpp -g -o program"); programmatically, then the exe is generated but, while running it I get a prompt saying "the exe is not compatible...... make see whether you need 32 bit or 62 bit"
I'm using dev c++ for the program! any solutions??
Replies
-
Abhishek RawalYou have to use g++ not gcc for C++ programs.
g++ prog.cpp -o prog
You can use gcc too, but you have to mention C++ std libs i.e -lstdc++
I prefer using g++ instead. -
Vishal SharmaAbhishek RawalYou have to use g++ not gcc for C++ programs.
g++ prog.cpp -o prog
You can use gcc too, but you have to mention C++ std libs i.e -lstdc++
I prefer using g++ instead.
As far as i know, g++ is only for compiling not to generate an exe... ๐ anyway, I'll try and get back here!
actually, gcc is also working fine if I do it in cmd. but when I'm using system() in my program, i get that prompt! -
Vishal Sharma
Okay, I tried g++ too. same thing happens!Abhishek RawalYou have to use g++ not gcc for C++ programs.
g++ prog.cpp -o prog
You can use gcc too, but you have to mention C++ std libs i.e -lstdc++
I prefer using g++ instead. -
Abhishek RawalCd to directory where executable file is stored then ./exefile
Doesn't this ^ executes the program ?
Well from what I tested in Linux, gcc doesn't compile C++ program but g++ do.
And it executes the program easily. -
Abhishek RawalTest with gcc (error in compiling) :
Test with g++ (successful compiling & executing) :
How you compiled without using -lstdc++ with 'gcc' ? ๐จ -
Vishal SharmaAbhishek RawalCd to directory where executable file is stored then ./exefile
Doesn't this ^ executes the program ?
Well from what I tested in Linux, gcc doesn't compile C++ program but g++ do.
And it executes the program easily.
through command prompt, if i go to the location where my .cpp file is, and use any of gcc or g++ commands, i get the .exe file and it runs.
but coming to the programming, when I use the
system("g++ program.cpp -o program");
then program.exe is created but when i run it either by program or manually by double clicking or through command prompt, i get this message!
"The version of this file is not compatible with the version of windows you are running. Check your computer's system information to see whether you need an x86 or x64 version of the program, and then contact software publisher"
I think I explained everything now! -
Abhishek Rawal
In Linux we can't open .exe file extension by double-clicking it, hence I have never tried executing like that for any C/C++ programs.Vishal0203when i run it either by program or manually by double clicking or through command prompt, i get this message!
"The version of this file is not compatible with the version of windows you are running. Check your computer's system information to see whether you need an x86 or x64 version of the program, and then contact software publisher"
I think I explained everything now!
Maybe Windows user can help you then.
Sorry,mate. -
Vishal SharmaAbhishek RawalTest with gcc (error in compiling) :
Test with g++ (successful compiling & executing) :
How you compiled without using -lstdc++ with 'gcc' ? ๐จ
This is what I'm getting all the time!! used both gcc and g++ -
Abhishek Rawalg++ -o program.exe program.cpp
The type : program
This should work! -
Vishal Sharma
same... It's pissing me off now! ๐Abhishek RawalJust type program in CMD shell. -
Abhishek Rawal
Edited, try this :Vishal0203same... It's pissing me off now! ๐
Abhishek Rawalg++ -o program.exe program.cpp
Then type : program
This should work! -
Vishal SharmaAbhishek RawalEdited, try this :
Its similar to what i typed before
there is no difference in
g++ program.cpp -o program
g++ program.cpp -o program.exe
and
g++ -o program.exe program.cpp
-o
is just for giving the name to exe file generated if we don't write -o then a.exe will be created since it is default..
all the three commands show the same message -
Abhishek RawalWell I know that, right ?
I am just using Trial & error method, if by any miracle it helps you out (which shouldn't logically) & solves your problem.
However,
It shouldn't compile when you use 'gcc' without using -lstdc++ but it is happening in your case because it simply can't link without using that (-lstc++), unless you use g++.
I don't know, but I think there might be problem in installing gcc properly. Or some libraries are missing ? -
Vishal SharmaI'm using the things which came along with the dev-c++ ... the bin folder already consist of all the dll's necessary! and compiling the program through dev has no problems.... it arises only in cmd
-
Abhishek Rawal
So, only last thing comes in my mind is :Vishal0203it arises only in cmd
Run CMD.exe as administrators. -
Vishal Sharma
or may be its a problem with OSAbhishek RawalSo, only last thing comes in my mind is :
Run CMD.exe as administrators. -
Abhishek Rawal
Could be. Have you tried this in any other PC ?Vishal0203or may be its a problem with OS
Or simply switch to Linux ๐ -
Vishal Sharma
haha.. that would be the last option! anyway, thanks for your patience!Abhishek RawalCould be. Have you tried this in any other PC ?
Or simply switch to Linux ๐ -
rahul69
Actually I think it is the compatibility problem, my guess is that u are using Windows 7 (maybe 64 bit) so the exe being created is not compatible, so if u need to run this, you can run this exe in windows XP (see if some friend of yours have XP installed, then take this exe, and run on his computer), or using virtualbox (with XP).Vishal0203haha.. that would be the last option! anyway, thanks for your patience!
Hope it helps -
Vishal Sharma
come on! I'm not that dumb ๐rahul69Actually I think it is the compatibility problem, my guess is that u are using Windows 7 (maybe 64 bit) so the exe being created is not compatible, so if u need to run this, you can run this exe in windows XP (see if some friend of yours have XP installed, then take this exe, and run on his computer), or using virtualbox (with XP).
Hope it helps
I know I'm using 32 bit OS.. so it must work fine! -
rahul69
Yes u r not! but once I faced a similar problem, and it happens when the program being used have some 16 bit dependencies, I once faced similar issue, I was using Win 7 32 bit at that time, seemingly it didn't supported the program, but that program ran in XP ๐ฒVishal0203come on! I'm not that dumb ๐
I know I'm using 32 bit OS.. so it must work fine!
You are reading an archived discussion.
Related Posts
๐
UGC(university Grants Commision) has announced that A student who is pursuing a B.sc course can apply for B.Tech and those who is pursuing engineering degree can apply for bachelor...
After the phenomenal launch of Microsoft Surface, though the tablet set the tech savvy audience on powerful discussions, the same didn't reflect on the company's sales charts. And therefore, not...
Yes CEans I was lucky to read this article that General Motors who is one of the best automobile manufacturers in world claimed to be at no.1 position in PATENT...
Skoda India has officially announced the new Skoda Octavia for Indian markets. The Octavia brand, darling of automobile enthusiasts all over India has just made a comeback. We wrote about...
We all knew that TATA,Hindustan and Maruti Suzuki ruled the Auto Industry in India till 1990's but After the globalization and people's love for foreign brands, all the things changed...