[SOLVED CLOSED] See addendum GCC ` backtick` CLI - what does it actually do ?
-
SOLVED case closed As expected - pkg-config DOES NOT integrate with just any Eclipse version / release. I got it working as expected in 2018-09! Sorry for wasting everybody time. Cheers It is my understanding that the characters enclosed in backticks execute and the result is passed as option(s) to the GCC.
`pkg-config --cflags gtk+-3.0`
I have added the backticks string to both GCC compiler and linkers options and still getting the usual "undefined reference" error. The tutorial does not explain much about implementing this backticks string. (Should it add library -l refernces ??) I woudl appreciate references or comments on this and suggestions how to actually resolve this issue. I am enclosing the complier / liker verbose output for information, and I am sorry to take so much bandwidth with it. Cheers CODE DELETED Addendum I do not like blaming problems elsewhere, BUT, this problem is really not related to using backtick syntax. After some trials it works as expected. There were few other problems AFTER I updated to latest version of IDE. So I down paddled to previous, working release and imported the GTK project there. Just build a clean GTK project and it works as expected. I am sorry for wasting everybody time with a problem related to flaky IDE. Cheers
-
SOLVED case closed As expected - pkg-config DOES NOT integrate with just any Eclipse version / release. I got it working as expected in 2018-09! Sorry for wasting everybody time. Cheers It is my understanding that the characters enclosed in backticks execute and the result is passed as option(s) to the GCC.
`pkg-config --cflags gtk+-3.0`
I have added the backticks string to both GCC compiler and linkers options and still getting the usual "undefined reference" error. The tutorial does not explain much about implementing this backticks string. (Should it add library -l refernces ??) I woudl appreciate references or comments on this and suggestions how to actually resolve this issue. I am enclosing the complier / liker verbose output for information, and I am sorry to take so much bandwidth with it. Cheers CODE DELETED Addendum I do not like blaming problems elsewhere, BUT, this problem is really not related to using backtick syntax. After some trials it works as expected. There were few other problems AFTER I updated to latest version of IDE. So I down paddled to previous, working release and imported the GTK project there. Just build a clean GTK project and it works as expected. I am sorry for wasting everybody time with a problem related to flaky IDE. Cheers
Run your backticked phrase (without backticks), redirected to a file. Then you can see what it injects into your command line when it's used backticked. Something like
pkg-config --cflags gtk+-3.0 > lookatmeclosely
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
-
Run your backticked phrase (without backticks), redirected to a file. Then you can see what it injects into your command line when it's used backticked. Something like
pkg-config --cflags gtk+-3.0 > lookatmeclosely
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
Thanks, but I know what is does - look at all the -I in the attached file. I think g++ also needs -l - libraries or library - for GTK. But I am not sure how to do it if I need more. Can I use similar method as pkg-config to get -l /-L ? Addendum Did some research and found this z@z-desktop:~$ pkg-config --libs gtk+-3.0 -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 That is what is needed. However adding another backtick string `pkg-config --libs gtk+-3.0` did not produced expected libraries. Will do some experimentation with that - it should work. More edit If I add `pkg-config --libs gtk+-3.0` to linker options I get about 20 additional -l libraries in output. However I still get "undefined reference " error. Later...
-
Thanks, but I know what is does - look at all the -I in the attached file. I think g++ also needs -l - libraries or library - for GTK. But I am not sure how to do it if I need more. Can I use similar method as pkg-config to get -l /-L ? Addendum Did some research and found this z@z-desktop:~$ pkg-config --libs gtk+-3.0 -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 That is what is needed. However adding another backtick string `pkg-config --libs gtk+-3.0` did not produced expected libraries. Will do some experimentation with that - it should work. More edit If I add `pkg-config --libs gtk+-3.0` to linker options I get about 20 additional -l libraries in output. However I still get "undefined reference " error. Later...
Make sure you are adding the --libs option to the link phase in your IDE. e.g. compiler flags : ... \`pkg-config --cflags gtk+-3.0\` ... linker flags : ... \`pkg-config --libs gtk+-3.0\` ... As an aside, you should be aware that the backtick idiom is a shell level construct, and is not anything specific to gcc. so you could do the following :
$ ls -l \`find . -name *.cpp\`
Which would produce a long listing of all cpp files in the current directory tree.
Keep Calm and Carry On
-
Make sure you are adding the --libs option to the link phase in your IDE. e.g. compiler flags : ... \`pkg-config --cflags gtk+-3.0\` ... linker flags : ... \`pkg-config --libs gtk+-3.0\` ... As an aside, you should be aware that the backtick idiom is a shell level construct, and is not anything specific to gcc. so you could do the following :
$ ls -l \`find . -name *.cpp\`
Which would produce a long listing of all cpp files in the current directory tree.
Keep Calm and Carry On
OK, putting wrong option may be one of the issues. I did put BOTH --cflag and --libs in complier and linker options. I also tried this combined syntax `pkg-config --cflags --libs gtk+-3.0` The compiler and linker verbose outputs looks OK ( too big to repost here ) , BUT the unresolved error is apparently different issue. I am enclosing what I posted in Eclipse forum here: This error has been posted years ago and there was NO SOLUTION, See this old post [b]However, this only solved the issue of adding all the header files manually. Now I encounter errors like "Function 'G_CALLBACK' could not be resolved". I tried to compile my source-code (the first example of the GTK3 tutorial) in a terminal using the simple "gcc `pkg-config --cflags gtk+-3.0` -o example-0 First_GTK_test.cpp `pkg-config --libs gtk+-3.0`" command and it works. So the issue must be an Eclipse setting issue.[/b] Every GTK tutorial is same - download / install GTK and run sample code in your editor... It is up to the user to figure out how to option complier / linker to "include sources and link libraries" Adding `pkg-config --cflags --libs gtk+-3.0` should work, I get expected verbose output , but it does not. Even after that is done the compilation will fail because #include is unresolved. Here is an output of whereis z@z-desktop:~$ whereis gtk.h gtk: z@z-desktop:~$ Any help woudl be appreciated End of Eclipse post. I am really at lost where the reference came from and unsure how to find gtk.h manually - where ? Appreciate all the help with such trivial issue. Cheers
-
OK, putting wrong option may be one of the issues. I did put BOTH --cflag and --libs in complier and linker options. I also tried this combined syntax `pkg-config --cflags --libs gtk+-3.0` The compiler and linker verbose outputs looks OK ( too big to repost here ) , BUT the unresolved error is apparently different issue. I am enclosing what I posted in Eclipse forum here: This error has been posted years ago and there was NO SOLUTION, See this old post [b]However, this only solved the issue of adding all the header files manually. Now I encounter errors like "Function 'G_CALLBACK' could not be resolved". I tried to compile my source-code (the first example of the GTK3 tutorial) in a terminal using the simple "gcc `pkg-config --cflags gtk+-3.0` -o example-0 First_GTK_test.cpp `pkg-config --libs gtk+-3.0`" command and it works. So the issue must be an Eclipse setting issue.[/b] Every GTK tutorial is same - download / install GTK and run sample code in your editor... It is up to the user to figure out how to option complier / linker to "include sources and link libraries" Adding `pkg-config --cflags --libs gtk+-3.0` should work, I get expected verbose output , but it does not. Even after that is done the compilation will fail because #include is unresolved. Here is an output of whereis z@z-desktop:~$ whereis gtk.h gtk: z@z-desktop:~$ Any help woudl be appreciated End of Eclipse post. I am really at lost where the reference came from and unsure how to find gtk.h manually - where ? Appreciate all the help with such trivial issue. Cheers
OK, this makes no sense Eclipse IDE has under includes /usr/include BUT I had to add this full path manually to get rid of " file doe snot exist " AKA undefined reference #include /usr/include/gtk-3.0/gtk/gtk.h ( < > won't show !!!! ) Now my first usage of GTK gives the "undefined reference " error - same as the very old post on Eclipse. In my view - the "top reference" is OK, but anything "bellow" is still unreferenced. This is a mess...
-
OK, this makes no sense Eclipse IDE has under includes /usr/include BUT I had to add this full path manually to get rid of " file doe snot exist " AKA undefined reference #include /usr/include/gtk-3.0/gtk/gtk.h ( < > won't show !!!! ) Now my first usage of GTK gives the "undefined reference " error - same as the very old post on Eclipse. In my view - the "top reference" is OK, but anything "bellow" is still unreferenced. This is a mess...
I'm fairly sure that the "undefined reference" is a link phase error, not a compile phase problem, so I don't think changing the headers or header search path will not help you
Vaclav_ wrote:
Eclipse IDE has under includes /usr/include
I don't use eclipse, but it looks to me like that's a path, so I think you would add /usr/include/gtk-3.0 assuming you're adding #include to your source file If you're getting the object files compiled successfully, but not getting the linking done then try, from a command line
gcc file1.o file2.o ... \`pkg-config --libs gtk+-3.0\` -o myapp
if you're compiling C++ code, use
g++
to link, not gcc, as that will link in stdlib++.o, and do anything else that C++ needs that plain C doesn't I don't see where you've said exactly what the undefined reference you're getting is. Its possible that its not a gtk+ function, but maybe a math (eg. abs, ceil cos) or function from another library.Keep Calm and Carry On
-
I'm fairly sure that the "undefined reference" is a link phase error, not a compile phase problem, so I don't think changing the headers or header search path will not help you
Vaclav_ wrote:
Eclipse IDE has under includes /usr/include
I don't use eclipse, but it looks to me like that's a path, so I think you would add /usr/include/gtk-3.0 assuming you're adding #include to your source file If you're getting the object files compiled successfully, but not getting the linking done then try, from a command line
gcc file1.o file2.o ... \`pkg-config --libs gtk+-3.0\` -o myapp
if you're compiling C++ code, use
g++
to link, not gcc, as that will link in stdlib++.o, and do anything else that C++ needs that plain C doesn't I don't see where you've said exactly what the undefined reference you're getting is. Its possible that its not a gtk+ function, but maybe a math (eg. abs, ceil cos) or function from another library.Keep Calm and Carry On
I am including , again, full complier / linker output. This is for purpose of discussion , I hope I can delete it later. Here is a full verbose output of complier and linker, note slew of "includes". In theory #include /gtk/gtk.h should work. If the error is flagged in IDE as " file not accessible" does it really matters if it is complier or linker error? ( The Eclipse refers to complier as "Linux GCC" then as "GCC C++ Complier" however the actuall options string starts with "g++". Semantics???) 10:50:35 **** Build of configuration Debug for project GTK_WIKI **** make all Building file: ../src/GTK_WIKI.cpp Invoking: GCC C++ Compiler g++ -I/usr/include/gtk-3.0/gtk -O0 -g3 -Wall -c -fmessage-length=0 `pkg-config --cflags --libs gtk+-3.0` -v -MMD -MP -MF"src/GTK_WIKI.d" -MT"src/GTK_WIKI.o" -o "src/GTK_WIKI.o" "../src/GTK_WIKI.cpp" Using built-in specs. COLLECT_GCC=g++ Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.12' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12) COLLECT_GCC_OPTIONS='-I' '/usr/include/gtk-3.0/gtk' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-pthread' '-I' '/usr/include/gtk-3.0' '-I' '/usr/include/at-spi2-atk/2.0' '-I' '/usr/include/at-spi-2.0' '-I' '/usr/include/dbus-1.0' '-I' '/usr/lib/x86_64-linux-gnu/dbus-1.0/include' '-I' '/usr/include/gtk-3.0' '-I' '/usr/include/gio-uni
-
I'm fairly sure that the "undefined reference" is a link phase error, not a compile phase problem, so I don't think changing the headers or header search path will not help you
Vaclav_ wrote:
Eclipse IDE has under includes /usr/include
I don't use eclipse, but it looks to me like that's a path, so I think you would add /usr/include/gtk-3.0 assuming you're adding #include to your source file If you're getting the object files compiled successfully, but not getting the linking done then try, from a command line
gcc file1.o file2.o ... \`pkg-config --libs gtk+-3.0\` -o myapp
if you're compiling C++ code, use
g++
to link, not gcc, as that will link in stdlib++.o, and do anything else that C++ needs that plain C doesn't I don't see where you've said exactly what the undefined reference you're getting is. Its possible that its not a gtk+ function, but maybe a math (eg. abs, ceil cos) or function from another library.Keep Calm and Carry On
-
The undefined ref is
gtk_window_new
defined in GtkWindow: GTK+ 3 Reference Manual[^]. No idea what OP is trying to do, as usual he has not explained.How did you pick that up? I copied the entire output posted at the top of this thread, and a) a search for "undefined" turned up nothing, and b) as currently shown, the compile completes successfully!! Doing a quick perusal of the rest of the thread, I didn't notice any further mention of exactly what was undefined. At this point, I have no idea what the problem is, since it looks to me like the compile/link is correct - -lgtk-3 is in the link options. Maybe Eclipse is doing something odd.
Keep Calm and Carry On
-
How did you pick that up? I copied the entire output posted at the top of this thread, and a) a search for "undefined" turned up nothing, and b) as currently shown, the compile completes successfully!! Doing a quick perusal of the rest of the thread, I didn't notice any further mention of exactly what was undefined. At this point, I have no idea what the problem is, since it looks to me like the compile/link is correct - -lgtk-3 is in the link options. Maybe Eclipse is doing something odd.
Keep Calm and Carry On
Here is the part of actual code #include /usr/include/gtk-3.0/gtk/gtk.h // edited so it show int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *label; cout << "WINDOW sample code" << endl; // prints /* Create the main, top level window */ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); And here is the tail of the compile / link process ./src/GTK_WIKI.o: In function `main': /media/z/DEV_COPY_LABEL/ECLIPSE_FOLDER/2020_228/work_228/GTK_WIKI/Debug/../src/GTK_WIKI.cpp:49: undefined reference to `gtk_window_new' collect2: error: ld returned 1 exit status makefile:45: recipe for target 'GTK_WIKI' failed make: *** [GTK_WIKI] Error 1 "make all" terminated with exit code 2. Build might be incomplete. 12:30:58 Build Failed. 3 errors, 2 warnings. (took 2s.647ms) Any actual , constructive help to solve the problem is appreciated. Cheers
-
How did you pick that up? I copied the entire output posted at the top of this thread, and a) a search for "undefined" turned up nothing, and b) as currently shown, the compile completes successfully!! Doing a quick perusal of the rest of the thread, I didn't notice any further mention of exactly what was undefined. At this point, I have no idea what the problem is, since it looks to me like the compile/link is correct - -lgtk-3 is in the link options. Maybe Eclipse is doing something odd.
Keep Calm and Carry On
It was right at the end of the build output in the previous message:
/media/z/DEV_COPY_LABEL/ECLIPSE_FOLDER/2020_228/work_228/GTK_WIKI/Debug/../src/GTK_WIKI.cpp:49: undefined reference to `gtk_window_new'
collect2: error: ld returned 1 exit status
make: *** [GTK_WIKI] Error 1
"make all" terminated with exit code 2. Build might be incomplete.10:50:37 Build Failed. 3 errors, 2 warnings. (took 2s.689ms)
Did you search the original which did not have any errors? I can only assume that there is an object file or library missing from the build. [edit] I have also tried to explain a number of times to OP that adding header files to a build has no effect on linker errors. [/edit]