Mingw resources - Example not working.

This is a discussion on Mingw resources - Example not working. within the Tech Board forums, part of the Community Boards category; I'm trying to link a resource file with mingw. I went to mingw's site, read this tutorial: Here's an example. ...

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Mingw resources - Example not working.

    I'm trying to link a resource file with mingw. I went to mingw's site, read this tutorial:

    Here's an example. The following is a code sample for a simple Windows program. Cut and paste it into a file named hello.c to try it out.
    Code:
       #include <windows.h>
    
       int WINAPI WinMain (HINSTANCE hInstance, 
                            HINSTANCE hPrevInstance, 
                            PSTR szCmdLine, 
                            int iCmdShow) 
       {
          MessageBox (NULL, "Hello", "Hello Demo", MB_OK);
          return (0);
       }
    If you want to create a Windows executable hello.exe, from a c file called hello.c, try the following:
    Code:
       gcc -c hello.c
    This compiles hello.c into an object file, hello.o
    Code:
       gcc -o hello hello.o -mwindows
    This creates an executable hello.exe from hello.o The -mwindows switch is needed to create Windows executables instead of console applications. It assures the appropriate Windows libraries are linked in for you. To get a console screen along with a standard windows application, add the -mconsole flag as well as -mwindows.

    If you have resources from a resource file (.rc) that also need to be added to your executable, you'll need to compile the resource file as well as your other source files and include the compiled resources when linking to create the executable. Here's an example that shows how to compile and link in a resource file named resfile.rc.
    Code:
       windres -o resfile.o resfile.rc
       gcc -o hello hello.o resfile.o -mwindows
    But, for making a .c / .cpp file into a .o, it doesnt work. And when I try linking my .o & .cpp, it deletes my cpp file! (Had to make a backup one -,-) I've tried this six times, it does the same thing each time
    Code:
    $ g++ -o hello hello.o -mwindows
    g++.exe: hello.o: No such file or directory
    g++.exe: no input files
    Likewise when I specify a directory for hello.o. Is this bad documentation or am I just a retard? -,-.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You need to compile source and resources to objects then link those objects together to create the executable. Using your example, you first invoke gcc(g++ for c++) with the '-c' switch which tells the compiler to emit an object file from the source:
    Code:
    g++ -c hello.cpp
    should output hello.o. Next you compile the resource script with windres, the resource compiler:
    Code:
    windres resfile.rc
    should output resfile.o. The final stage is linking the two objects together with some default libraries to create the final executable. The linker, ld, is invoked implicitly by the compiler:
    Code:
    g++ -o hello.exe hello.o resfile.o -mwindows
    . Make sure you use g++ to compile c++ source code as gcc doesn't always work for c++ (gcc is the 'c' compiler).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-07-2009, 12:31 PM
  2. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  3. Resources, icon, resources....
    By bluehead in forum Windows Programming
    Replies: 11
    Last Post: 05-26-2002, 06:59 AM
  4. Compiling Resources In MinGW
    By Okiesmokie in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 04:16 PM
  5. MinGW Resource
    By Okiesmokie in forum Windows Programming
    Replies: 1
    Last Post: 03-05-2002, 08:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21