Makefile problem

This is a discussion on Makefile problem within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I have followed a tutorial for creating a simple gtk+2 application using MinGW. The c source file looks alright, ...

  1. #1
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286

    Makefile problem

    Hello,

    I have followed a tutorial for creating a simple gtk+2 application using MinGW. The c source file looks alright, but the Makefile seems to contain an error:

    Code:
    CC=gcc
    CFLAGS=`pkg-config --cflags --libs gtk+-2.0`
    CFLAGS+=-mwindows
    SRC=hello.c
    OBJ=$(SRC:.c=.o)
    OUT=hello.exe
    
    all: $(OUT)
    	rm $(OBJ) #Remove .o
    
    $(OBJ) :
    	$(CC) $(SRC) $(CFLAGS) -c #Create .o
    
    $(OUT) : $(OBJ)
    	$(CC) $(OBJ) $(CFLAGS) -o $@ #Link .o
    First, I wonder why it says CC=gcc when I'm using mingw. But that's not the problem. My compiler complains and says "`pkg-config: No such file or directory". I read somewhere that the backquotes used in that line is a unix/linux thing that the windows shell doesn't understand. What should I use instead?
    Come on, you can do it! b( ~_')

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    Take a look over there: http://www.gtkforums.com/viewtopic.php?p=2084#2084

    In order for pkg-config to work, the path where all the .pc files live must be set.

  3. #3
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    Thanks for the reply. I read the post, but there's a couple of things that's unclear to me:

    First, what is a .ps file? Why do I have to set a path, and how do I do it? Do those things live? :S

    "You can do this every time you start a MSYS session"... But I don't run MSYS, I run Emacs and compile via the compile command. Can I integrate the line
    set PKG_CONFIG_PATH=/mingw/lib/pkgconfig into the Makefile somehow?
    Come on, you can do it! b( ~_')

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    MinGW is not a compiler. gcc is a compiler. Hence your command to compile is "gcc".

    We just did setting environment variables not too long ago -- unless you plan to set a lot of different PKG_CONFIG_PATHs, just set it once (control panel -> system -> advanced tab).

  5. #5
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    I want my application as portable as possible, hence I would rather write something into my makefile than change/add some system variable. Is it possible to do it only by changing in the makefile? Btw, do you mean "System properties->Environment variables->System variables"? I didn't find any PKG_CONFIG_PATH, but maybe I was looking at the wrong place.
    Come on, you can do it! b( ~_')

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by TriKri View Post
    I want my application as portable as possible, hence I would rather write something into my makefile than change/add some system variable. Is it possible to do it only by changing in the makefile? Btw, do you mean "System properties->Environment variables->System variables"? I didn't find any PKG_CONFIG_PATH, but maybe I was looking at the wrong place.
    Nah, you ADD a new path called PKG_CONFIG_PATH (or whatever it is that you want to have before your compile command).

    You can also do "set ... " in a command prompt window and start (x)emacs from there.

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

  7. #7
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    Now I have set a variable called PKG_CONFIG_PATH, but it still doesn't work. I have tried to set it to both /mingw/lib/pkgconfig and /program files/mingw/lib/pkgconfig and C:/program files/mingw/lib/pkgconfig, both with forwardslashes and with backslashes, since mingw is installed under C:\Program Files\MinGW, and all other system variables uses backslashes.

    So, this is what it says:
    Code:
    -*- mode: compilation; default-directory: "d:/Work/cpp/GTK+ setup/" -*-
    Compilation started at Thu Jun 26 00:09:43
    
    mingw32-make -k 
    gcc hello.c `pkg-config --cflags --libs gtk+-2.0` -mwindows -c #Create .o
    cc1.exe: error: unrecognized command line option "-fcflags"
    cc1.exe: error: unrecognized command line option "-flibs"
    gcc: `pkg-config: No such file or directory
    gcc: gtk+-2.0`: No such file or directory
    gcc: #Create: No such file or directory
    gcc: .o: No such file or directory
    mingw32-make: *** [hello.o] Error 1
    mingw32-make: Target `all' not remade because of errors.
    
    Compilation exited abnormally with code 2 at Thu Jun 26 00:09:43
    Come on, you can do it! b( ~_')

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Your makefile assumes that the shell you use translates commands between the `` is translated into arguments to gcc, which appears to not be the case.

    A quick hack would be to run
    Code:
    pkg-config --cflags --libs gtk+-2.0
    and then set the gcc flags to the ouptut of that comand instead.

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

  9. #9
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    Do you mean like this:

    Code:
    CC=gcc
    CFLAGS=$(PKG_CONFIG) #This code have been moved down there
    CFLAGS+=-mwindows
    SRC=hello.c
    OBJ=$(SRC:.c=.o)
    OUT=hello.exe
    
    all: $(OUT)
    	rm $(OBJ) #Remove .o
    
    $(OBJ) :
    	$(CC) $(SRC) $(CFLAGS) -c #Create .o
    
    $(OUT) : $(OBJ)
    	$(CC) $(OBJ) $(CFLAGS) -o $@ #Link .o
    
    $(PKG_CONFIG) : `pkg-config --cflags --libs gtk+-2.0` #This line is new
    I suck at creating makefiles, but I would guess that's a variable I have crearted. Now it doesn't complain about the same things at least, but it says "gdk/gdk.h: No such file or directory", so I guess the pkg-config didn't work...
    Come on, you can do it! b( ~_')

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. problem with Makefile separator
    By luca in forum Tech Board
    Replies: 6
    Last Post: 01-15-2007, 09:20 AM
  3. Problem with makefile, how to use the -lm oh this?
    By Nazgulled in forum C Programming
    Replies: 1
    Last Post: 04-07-2006, 01:29 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  5. Replies: 5
    Last Post: 11-07-2005, 10:34 PM

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