Joe Barr
Joe Barr

Reputation: 251

Compiling WIN32 code with GCC

I have tried to compile some C++ WIN32 code with GCC through DevC++ (MinGW GCC). It seams that it failed to link the objects and it didn't give me a clear error message: "[PathToSource] > Error 1".

Tried the same thing with Eclipse (MinGW GCC) and it compiled. However, not all of the resources show as I have an icon set to compile as the icon of the application, it's loaded from the resource files. I also get a console window in the background as I run the application.

What is the cause of this? How can I make the resource files compile with the code and also avoid the loading of a console window in the background.

I was also wondering if there's a way to compile WIN32 code in Linux through GCC, or a way to port it for the same compiler.

Upvotes: 4

Views: 12471

Answers (3)

Joe Barr
Joe Barr

Reputation: 251

Resource files in Eclipse:

In the Build Steps of the project, there needs to be entered the command and the full path to the resource and its output file.

windres ../Resources/resource_file.rc -o ../Debug/resource_file.o

In the Tool Settings of the project in the linker options, the path to the resource output file needs to be added in order for the resources to be linked into the executable file.

../Debug/resource_file.o

Avoid the console window:

A linker flag needs to be specified for GUI only.

-mwindows

In Eclipse:

Enter the flag in the project Tool Settings in Linker flags.

Upvotes: 1

silent
silent

Reputation: 2904

Try compiling in command prompt and see what happens.

for your resource file try this in the command prompt.

windres resource_file.rc -o resource_file.o and finally to build your code, g++ resource_file.o -o app.exe app.cpp

Upvotes: 4

user295190
user295190

Reputation:

I have tried to compile some C++ WIN32 code with GCC through DevC++ (MinGW GCC). It seams that it failed to link the objects and it didn't give me a clear error message: "[PathToSource] > Error 1".

Have you included a path to the Windows SDK? On my computer it is at:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64

(Note I have Visual Studios Installed on my Computer)

Compile you program with the appropriate gcc library settings.

Tried the same thing with Eclipse (MinGW GCC) and it compiled. However, not all of the resources show as I have an icon set to compile as the icon of the application, it's loaded from the resource files. I also get a console window in the background as I run the application.

Check the resource settings to see where Eclipse is referencing your Windows Library.

What is the couse of this? How can I make the resource files compile with the code and also avoid the loading of a console window in the background.

Develop your applications in Visual Studio. If you cannot afford Visual Studio and you are a hobby programm consider Visual Studios Express.

I was also wondering if there's a way to compile WIN32 code in Linux through GCC, or a way to port it for the same compiler.

If you mean the WINAPI, then no, not as far as I know. If you want compatibility you should stick with the standard C++ library.

There are, however, universal libraries that you might find useful:

  1. http://sourceware.org/pthreads-win32/
  2. http://stdcxx.apache.org/#platforms
  3. http://www.gtk.org/download-windows.html
  4. Cross Platform Lbiraries (Stackoverflow)

Upvotes: 2

Related Questions