Reputation: 445
Sorry for the newbie question, this is my first time working with GTK in Linux.
Found several ok tutorials on making my first program using GTK in Linux. For the sake of this question I am referring to this tutorial https://developer.gnome.org/gtk3/stable/gtk-getting-started.html. So I copied and pasted the code, and then tried running it from the command line with
gcc `pkg-config --cflags gtk+-3.0` -o example-0 /home/username/project/example-0.c `pkg-config --libs gtk+-3.0`
On the first example (in that link) it seems to do nothing, and allows me to enter more commands. For the second example is gives me a cursor (>) like it is looking for input. Both should open a GUI window, but they don't.
I got a gut feeling the files need to be in a certain directory. But none of the tutorials really go into where the files should be placed.
I tried a few other tutorials and got the exact same results. So I have to assume something on my end is setup wrong.
I am certain GTK 3 is installed
sudo apt-get install libgtk-3-dev
And I checked that pkg-config
is installed (saw this suggested while looking for answers)
UPDATE
Ok I think I have partially sorted it out. I was under the impression that gcc
would output the result of the code. It appears it creates a file, that is places in /home/username/
. I guess I need to know if gcc is able to show the output? If not how do I run that file? I am not see a way to execute the file it makes.
Upvotes: 1
Views: 575
Reputation: 445
Ok after digging around in C++ tutorials I think I found the solution. The problem is I did not realize how gcc works combined with a bit of ignorance on how Linux does some stuff. Those GTK "beginner" tutorials are for people with a good working knowledge of programming in C++ in Linux. I had done C++ but in Visual Studio in windows, and even then that was 6 or 7 years ago.
So basically gcc makes a new compiled file, the -o
option lets you name the file (otherwise gcc names it "a.out") and gcc allows you to specify the directory the compiled file is saved to (important detail). Then you use ./filesname
to run it, that is if you are in the correct directory (cd).
So what I did is first change the directory that I am on, in the terminal, to where I am saving my programs files. Below is an example of what my terminal looks like leading up to successfully opening of a GTK GUI window (note I ditched the "example-0" naming as is seems to cause an issue)
username@pcname:~$ cd /somefolder/projects
username@pcname:~/somefolder/projects$ gcc `pkg-config --cflags gtk+-3.0` -o myprog myprog.c `pkg-config --libs gtk+-3.0`
username@pcname:~/somefolder/projects$ ./myprog
And just like that all is working.
Just for clarity here is each command separated out, one just needs to change the folder and file names
cd /somefolder/projects
gcc `pkg-config --cflags gtk+-3.0` -o myprog myprog.c `pkg-config --libs gtk+-3.0`
./myprog
Upvotes: 2