Thread: Compiler error

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    4

    Compiler error

    I've been trying to use my GCC C compiler and in my program it includes "windows.h" and the compiler says that it's not a file or directory but i found the file in "/usr/include/". can anyone figure this out?
    Last edited by HisZd; 04-16-2008 at 10:50 AM.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by HisZd View Post
    I've been trying to use my GCC C compiler and in my program it includes "windows.h" and the compiler says that it's not a file or directory but i found the file in "/usr/include/".
    can anyone figure this out?
    I think you'll find it difficult to compile a Windows program on Linux...

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    As brewbuck hints, any source code that includes windows.h is using windows-specific code, which means one of a few things:
    1. You have some configuration settings in the build script wrong.
    Some applications come with settings for what OS you compile it for - if it's set for Windows on a linux machine, it's obviously not going to work. Check the README-file or other documentation that came with the source, and see if there's anything telling you how to make the configuration settings right.

    2. You need to port the code to Linux (or whatever Unix-like OS you are using).
    3. The source code is including windows.h for no apparently good reason.
    For both of the type 2 & 3 problem, the solution is to remove Windows.h and see if it compiles. If it doesn't compile without errors, then you have to figure out what the Windows system calls are doing, and what the equivalent Linux calls are. The difficulty here ranges from trivial to very difficult depending on the type of calls and your experience with Windows and Linux.

    4. You should do something else.
    Maybe the task of trying to compile this code on Linux is not what you should be doing at all - is there some other source that could achieve the same thing, but more suitable for Linux, for example.

    Obviously, if this is code you have written yourself, then you obviously aren't in category 1 above. If it's someone elses code, perhaps you can tell us what the code is (assuming you got it from the web or such - if it's something your friend wrote, then ask your friend), since someone may know of some other source of code that achieves the same thing.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    4
    Well how do i make it so that i can make a new xwindow in linux?

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You mean you have a Windows app and you want to use it under XWindows - well, despite the relative similarity in naming, it's like trying to make a Ford Escort engine fit in a old-style VW Beetle - it's kind of complicated, because they are completely different designs (For those less familiar with cars: A Ford Escort is a front wheel drive, engine at the front car, a VW Beetle of the old type has the engine over the rear driving wheels).

    What does your application do?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    4
    Here is the code this is my first app using windows.h(hence the "Hello World!")
    Code:
    #include <windows.h>
    
    int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
    {
    	MessageBox(NULL, "\tHello World!", "My first windows app.",NULL);
    	return 0;
    }

  7. #7
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    This code you posted is for the Windows operating system. I am not familiar with GUIs in Linux but perhaps you could look into wxWidgets or QT or something like that. I am assuming you are using linux?
    What is C++?

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    If you're following a Windows programming tutorial, forget it. It's not going to teach you how to do GUIs under Linux. There is very little information that you can even transfer, and what there is is theoretical.

    What you need is a tutorial that uses Qt, wxWidgets or GTK+.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by HisZd View Post
    Here is the code this is my first app using windows.h(hence the "Hello World!")
    Code:
    #include <windows.h>
    
    int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
    {
    	MessageBox(NULL, "\tHello World!", "My first windows app.",NULL);
    	return 0;
    }
    So you want something similar but for Linux. Okay, but you're not going to get there by modifying this code. The Linux version will literally not have a single element in common with this program.

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    4
    I figured that but i just wanted a header file that kinda does the same thing that "windows.h" does but for linux.

  11. #11
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by HisZd View Post
    I figured that but i just wanted a header file that kinda does the same thing that "windows.h" does but for linux.
    On Linux the windowing architecture is fundamentally different, because there is an extra layer of abstraction not present on Windows, known as the "toolkit." To write window programs on Linux your first decision will be which toolkit to use. There are many. Qt and GTK seem to be the most popular, although there are MANY others.

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, like I said, it's like fitting a "engine in the front front-wheel drive" engine into a car that has the engine and driving wheels at the back - there is just about nothing that is the same. Of course, most bolts will still come out if you turn the counterclockwise in both cases, and pistons go "up and down" inside the cylinders, etc. But the mechanical fittings are ALL going to be very different, and a lot of "messing about" will be needed to get it to even fit.

    Likewise, the C language is the same, but the way you tell XWindows to show a dialog box will not be at all similar (the only bit that MAY be similar is the "Hello World" - but don't hold me to that one).

    This is a sample X11 program (although it appears to be missing the name of some header file):
    http://www.linuxjournal.com/files/li...79/4879l1.html

    I believe it should be:
    #include <X11/Xlib.h>
    in that first line.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM