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??

Replies

  • Abhishek Rawal
    Abhishek Rawal
    You 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 Sharma
    Vishal Sharma
    Abhishek Rawal
    You 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
    Vishal Sharma
    Abhishek Rawal
    You 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.
    Okay, I tried g++ too. same thing happens!
  • Abhishek Rawal
    Abhishek Rawal
    Cd 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 Rawal
    Abhishek Rawal
    Test with gcc (error in compiling) :
    1

    Test with g++ (successful compiling & executing) :
    2

    How you compiled without using -lstdc++ with 'gcc' ? ๐Ÿ˜จ
  • Vishal Sharma
    Vishal Sharma
    Abhishek Rawal
    Cd 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
    Abhishek Rawal
    Vishal0203
    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!
    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.

    Maybe Windows user can help you then.
    Sorry,mate.
  • Vishal Sharma
    Vishal Sharma
    Abhishek Rawal
    Test with gcc (error in compiling) :
    1

    Test with g++ (successful compiling & executing) :
    2

    How you compiled without using -lstdc++ with 'gcc' ? ๐Ÿ˜จ

    This is what I'm getting all the time!! used both gcc and g++
  • Abhishek Rawal
    Abhishek Rawal
    g++ -o program.exe program.cpp

    The type : program

    This should work!
  • Vishal Sharma
    Vishal Sharma
    Abhishek Rawal
    Just type program in CMD shell.
    same... It's pissing me off now! ๐Ÿ˜•
  • Abhishek Rawal
    Abhishek Rawal
    Vishal0203
    same... It's pissing me off now! ๐Ÿ˜•
    Edited, try this :

    Abhishek Rawal
    g++ -o program.exe program.cpp

    Then type : program

    This should work!
  • Vishal Sharma
    Vishal Sharma
    Abhishek Rawal
    Edited, 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 Rawal
    Abhishek Rawal
    Well 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 Sharma
    Vishal Sharma
    I'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
    Abhishek Rawal
    Vishal0203
    it arises only in cmd
    So, only last thing comes in my mind is :
    Run CMD.exe as administrators.
  • Vishal Sharma
    Vishal Sharma
    Abhishek Rawal
    So, only last thing comes in my mind is :
    Run CMD.exe as administrators.
    or may be its a problem with OS
  • Abhishek Rawal
    Abhishek Rawal
    Vishal0203
    or may be its a problem with OS
    Could be. Have you tried this in any other PC ?
    Or simply switch to Linux ๐Ÿ˜
  • Vishal Sharma
    Vishal Sharma
    Abhishek Rawal
    Could be. Have you tried this in any other PC ?
    Or simply switch to Linux ๐Ÿ˜
    haha.. that would be the last option! anyway, thanks for your patience!
  • rahul69
    rahul69
    Vishal0203
    haha.. that would be the last option! anyway, thanks for your patience!
    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).
    Hope it helps
  • Vishal Sharma
    Vishal Sharma
    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).
    Hope it helps
    come on! I'm not that dumb ๐Ÿ˜›
    I know I'm using 32 bit OS.. so it must work fine!
  • rahul69
    rahul69
    Vishal0203
    come on! I'm not that dumb ๐Ÿ˜›
    I know I'm using 32 bit OS.. so it must work fine!
    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 ๐Ÿ˜ฒ

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...