0

I'm beginning to teach myself a bit of C++ these days off, and I decided to learn some GUI programming in the meantime. Thing is, it just won't compile, either using GTK (Windows bundle 3.6.4) or wxWidgets (3.0.0). The error I get is similar for both, so I'm sticking with GTK+ for this question.

After 5 days (7 recompiles of wx, many tutorials, SO questions and google), this is how I'm trying to compile the code (I'm under Windows 7, 64 bits, and it's not an option to switch to Linux right now):

@echo off

set cygpath=C:\Cygwin\bin
set filename=simple

%cygpath%\bash.exe -c "gcc $(pkg-config --cflags gtk+-3.0) -o %filename% %filename%.c $(pkg-config --libs gtk+-3.0)"

echo.
pause

But the only output I get is this (backtilts instead of $() returns the same thing):

: Invalid argument
: Invalid argument

I tried the same without Cygwin at first, but the results were:

gcc: error: $(pkg-config: No such file or directory
gcc: error: gtk+-3.0): No such file or directory
gcc: error: $(pkg-config: No such file or directory
gcc: error: gtk+-3.0): No such file or directory
gcc: error: unrecognized command line option '--cflags'
gcc: error: unrecognized command line option '--libs'

Using quotes or double quotes didn't help at all. I tried all these in both cygwin-bash or Windwos prompt

I'm totally new to C++, wxWidgets and GTK+ and I already saw this, but since it didn't solve my problem and I can't comment because of reputation, I thought I had to open a new question.

Also, I changed the compiler to TDM-GCC because I couldn't compile wx with MinGW. Is this somewhat related? What am I missing here?

Thanks in advance for any help.

EDIT: Sorry, just realized that the sample was written in C, not C++. I'm adding the tag now. (However, the error is the same with the C++ code I'm using for wx, so I'm keeping the C++ tag.)

Community
  • 1
  • 1
  • It seems that `cmd.exe` doesn't do inline variable substitution in strings. (Windows gurus please confirm or refute that.) –  Dec 31 '13 at 22:01
  • @H2CO2: Yes, it does replace variables in strings. Except in `cmd` variables are spelled `%LIKE_THIS%` not `$(LIKE_THIS)`. – Billy ONeal Dec 31 '13 at 22:02
  • @BillyONeal 3, not 2 (I would miss my double negative charge). And that seems pretty logical, but does `%it --work with /commands/too%`? –  Dec 31 '13 at 22:06
  • @H2CO3: No, there is no command support that way. – Billy ONeal Dec 31 '13 at 22:07
  • @H2CO3: And the Windows org is aggressively pushing people to use PowerShell instead of changing `cmd` due to the massive backcompat headache that would cause. – Billy ONeal Dec 31 '13 at 22:07
  • 3
    @BillyONeal Ugh... why can't everyone just use Bash...!? (rhetorical) –  Dec 31 '13 at 22:08
  • Just write a bash script and then have your .bat file call bash.exe with the bash script – Brandin Dec 31 '13 at 23:29
  • What gets output if you run the command: `%cygpath%\bash.exe -c "echo gcc $(pkg-config --cflags gtk+-3.0) -o %filename% %filename%.c $(pkg-config --libs gtk+-3.0)"` – Michael Burr Jan 01 '14 at 00:30
  • @Brandin thats exactly what I'm doing. `%cygpath%\bash.exe` is tha call for it. –  Jan 01 '14 at 16:12
  • @MichaelBurr `gcc -mms-bitfields -IC:/gtk/include/gtk-3.0 -IC:/gtk/include/cairo -IC:/gtk/incl ude/pango-1.0 -IC:/gtk/include/atk-1.0 -IC:/gtk/include/cairo -IC:/gtk/include/p ixman-1 -IC:/gtk/include -IC:/gtk/include/freetype2 -IC:/gtk/include -IC:/gtk/in clude/libpng15 -IC:/gtk/include/gdk-pixbuf-2.0 -IC:/gtk/include/libpng15 -IC:/gt -o simple simple.c -LC:/gtk/lib -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole 32 -Wl,-luuid -lpangocairo-1.0 -lpangoft2-1.0 -lfreetype -lfontconfig -lpangowin` (cutting it a bit because of SO) –  Jan 01 '14 at 16:13
  • @Ryu No I mean rather than stuffing all the commands into the -c parameter, you would have an easier time if you write the commands into a dedicated "myscript.sh" file and then do `%cygpath%\bash.exe myscript.sh` – Brandin Jan 01 '14 at 16:14
  • @Brandin oh, this. Because that was the way I got to work, no deep meaning. Besides, in the answer bellow, this was suggested too, and didn't work either. –  Jan 01 '14 at 16:17
  • @Ryu: it looks like the compiler maybe doesn't like the Windows-style paths with drive letters. You may need to somehow convince `pkg-config` to spit out paths using a Cygwin mount point, such as `/c/gtk/include/cairo` or `/cygdrive/c/gtk/include/cairo` instead of `C:/gtk/include/cairo`. If you can't do that, perhaps a simple filter script can do that for you. – Michael Burr Jan 02 '14 at 02:29
  • @MichaelBurr I see... Actually, I found that, setting variable with the results for `pkg-config --cflags --libs gtk+-3.0`, it seams to stop complaining. So, I'm sticking with this for now. Thanks for your time. –  Jan 03 '14 at 20:38

1 Answers1

1

This is NOT a gcc issue. This is a scripting/shell/bash/environment issue.

gcc: error: $(pkg-config: No such file or directory

This line denotes that 'gcc' saw $(pkg-config where it was expecting a file name; Linux apps expect command-line substitution to have been done for them by the shell invoking them.

That means that the shell did not consume $(pkg-config --cflags gtk+-3.0) and perform substitution on it.

You might want to try making a bash script, gtkcc.sh, which does this for you and inserts the relevant parameters in the appropriate places.

#!/bin/bash

# usage: gtkcc.sh <filename>
filename="$1"; shift
if [ -z "${filename}" ]; then echo "Usage: $0 <filename>"; exit 255; fi
if [ ! -f "${filename}.c" ]; then echo "Cannot find ${filename}.c"; exit 255; fi

gtkCFLAGS="$(pkg-config --cflags gtk+-3.0)"
gtkLDFLAGS="$(pkg-config --libs gtk+-3.0)"

cmd="gcc ${gtkCFLAGS} -o \"${filename}\" \"${filename}.c\" ${gtkLDFLAGS}"
echo $cmd >${TMP}/gtkcc.log
eval $cmd

Save as gtkcc.sh or gtkcc, chmod a+rx gtkcc.sh

Change your bat file to invoke:

%cygpath%\bash.exe gtkcc.sh %filename%

If it doesn't work, start a bash and consult ${TMP}/gtkcc.log, otherwise you can comment out the echo line.

kfsone
  • 23,617
  • 2
  • 42
  • 74
  • The error you're referring only shows when I call gcc from the windows terminal. Using Cygwin's bash, the error is `: Invalid argument`. I also tried your suggestion and it didn't work, giving now this: `: No such file or directoryash gtkcc.sh: line 2: $'\r': command not found gtkcc.sh: line 4: $'shift\r': command not found gtkcc.sh: line 14: syntax error: unexpected end of file` –  Dec 31 '13 at 23:27
  • That means you have Windows line endings in the .sh file and bash is barfing on the character. You need to convert to Unix file endings with `dos2unix gtkcc.sh`. http://stackoverflow.com/questions/11616835/cygwin-r-command-not-found-bashrc-bash-profile Another option would be to get into the habit of using something like Notepad++ (which will let you specify line ending mode) rather than notepad. – kfsone Jan 01 '14 at 02:04
  • I actually code with Emacs or Notepad++ (though I only use NP++ for quick edits), but anyway... I changed the EOL to Unix, and now it stoped the long error. The other one is still there, though. The `: Invalid Argument`, I mean. –  Jan 01 '14 at 16:11
  • What - if anything - is it writing to /tmp/gtkcc.log? – kfsone Jan 01 '14 at 20:02
  • Only `: Invalid Argument`. But it seams that, if I set a variabla with the contents of `pkg-config --cflags --libs gtk+-3.0`, Windows stops complaining and start to work. So I'm sticking with this for now. Thanks for your time and sorry for anything. –  Jan 03 '14 at 20:41