Linker errors when compiling against glib…?












1














I'm having trouble compiling a simple, sample program against glib on Ubunutu. I get these errors. I can get it to compile but not link with the -c flag. Which I believe means I have the glib headers installed, but it's not finding the shared object code. See also the make file below.



$> make re
gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 re.c -o re
/tmp/ccxas1nI.o: In function `print_uppercase_words':
re.c:(.text+0x21): undefined reference to `g_regex_new'
re.c:(.text+0x41): undefined reference to `g_regex_match'
re.c:(.text+0x54): undefined reference to `g_match_info_fetch'
re.c:(.text+0x6e): undefined reference to `g_print'
re.c:(.text+0x7a): undefined reference to `g_free'
re.c:(.text+0x8b): undefined reference to `g_match_info_next'
re.c:(.text+0x97): undefined reference to `g_match_info_matches'
re.c:(.text+0xa7): undefined reference to `g_match_info_free'
re.c:(.text+0xb3): undefined reference to `g_regex_unref'
collect2: ld returned 1 exit status
make: *** [re] Error 1


Makefile used:



# Need to installed libglib2.0-dev some system specific install that will
# provide a value for pkg-config
INCLUDES=$(shell pkg-config --libs --cflags glib-2.0)
CC=gcc $(INCLUDES)
PROJECT=re

# Targets
full: clean compile

clean:
rm $(PROJECT)

compile:
$(CC) $(PROJECT).c -o $(PROJECT)


.c code being compiled:



#include <glib.h>    

void print_upppercase_words(const gchar *string)
{
/* Print all uppercase-only words. */

GRegex *regex;
GMatchInfo *match_info;

regex = g_regex_new("[A-Z]+", 0, 0, NULL);
g_regex_match(regex, string, 0, &match_info);

while (g_match_info_matches(match_info))
{
gchar *word = g_match_info_fetch(match_info, 0);
g_print("Found %sn", word);
g_free(word);
g_match_info_next(match_info, NULL);
}

g_match_info_free(match_info);
g_regex_unref(regex);
}

int main()
{
gchar *string = "My body is a cage. My mind is THE key.";

print_uppercase_words(string);
}


Strangely, when I run glib-config it doesn't like that command -- though I don't know how to tell bash or make how to just use one over the other when it complains that gdlib-config is in these 2 packages.



$> glib-config
No command 'glib-config' found, did you mean:
Command 'gdlib-config' from package 'libgd2-xpm-dev' (main)
Command 'gdlib-config' from package 'libgd2-noxpm-dev' (main)
glib-config: command not found









share|improve this question





























    1














    I'm having trouble compiling a simple, sample program against glib on Ubunutu. I get these errors. I can get it to compile but not link with the -c flag. Which I believe means I have the glib headers installed, but it's not finding the shared object code. See also the make file below.



    $> make re
    gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 re.c -o re
    /tmp/ccxas1nI.o: In function `print_uppercase_words':
    re.c:(.text+0x21): undefined reference to `g_regex_new'
    re.c:(.text+0x41): undefined reference to `g_regex_match'
    re.c:(.text+0x54): undefined reference to `g_match_info_fetch'
    re.c:(.text+0x6e): undefined reference to `g_print'
    re.c:(.text+0x7a): undefined reference to `g_free'
    re.c:(.text+0x8b): undefined reference to `g_match_info_next'
    re.c:(.text+0x97): undefined reference to `g_match_info_matches'
    re.c:(.text+0xa7): undefined reference to `g_match_info_free'
    re.c:(.text+0xb3): undefined reference to `g_regex_unref'
    collect2: ld returned 1 exit status
    make: *** [re] Error 1


    Makefile used:



    # Need to installed libglib2.0-dev some system specific install that will
    # provide a value for pkg-config
    INCLUDES=$(shell pkg-config --libs --cflags glib-2.0)
    CC=gcc $(INCLUDES)
    PROJECT=re

    # Targets
    full: clean compile

    clean:
    rm $(PROJECT)

    compile:
    $(CC) $(PROJECT).c -o $(PROJECT)


    .c code being compiled:



    #include <glib.h>    

    void print_upppercase_words(const gchar *string)
    {
    /* Print all uppercase-only words. */

    GRegex *regex;
    GMatchInfo *match_info;

    regex = g_regex_new("[A-Z]+", 0, 0, NULL);
    g_regex_match(regex, string, 0, &match_info);

    while (g_match_info_matches(match_info))
    {
    gchar *word = g_match_info_fetch(match_info, 0);
    g_print("Found %sn", word);
    g_free(word);
    g_match_info_next(match_info, NULL);
    }

    g_match_info_free(match_info);
    g_regex_unref(regex);
    }

    int main()
    {
    gchar *string = "My body is a cage. My mind is THE key.";

    print_uppercase_words(string);
    }


    Strangely, when I run glib-config it doesn't like that command -- though I don't know how to tell bash or make how to just use one over the other when it complains that gdlib-config is in these 2 packages.



    $> glib-config
    No command 'glib-config' found, did you mean:
    Command 'gdlib-config' from package 'libgd2-xpm-dev' (main)
    Command 'gdlib-config' from package 'libgd2-noxpm-dev' (main)
    glib-config: command not found









    share|improve this question



























      1












      1








      1


      1





      I'm having trouble compiling a simple, sample program against glib on Ubunutu. I get these errors. I can get it to compile but not link with the -c flag. Which I believe means I have the glib headers installed, but it's not finding the shared object code. See also the make file below.



      $> make re
      gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 re.c -o re
      /tmp/ccxas1nI.o: In function `print_uppercase_words':
      re.c:(.text+0x21): undefined reference to `g_regex_new'
      re.c:(.text+0x41): undefined reference to `g_regex_match'
      re.c:(.text+0x54): undefined reference to `g_match_info_fetch'
      re.c:(.text+0x6e): undefined reference to `g_print'
      re.c:(.text+0x7a): undefined reference to `g_free'
      re.c:(.text+0x8b): undefined reference to `g_match_info_next'
      re.c:(.text+0x97): undefined reference to `g_match_info_matches'
      re.c:(.text+0xa7): undefined reference to `g_match_info_free'
      re.c:(.text+0xb3): undefined reference to `g_regex_unref'
      collect2: ld returned 1 exit status
      make: *** [re] Error 1


      Makefile used:



      # Need to installed libglib2.0-dev some system specific install that will
      # provide a value for pkg-config
      INCLUDES=$(shell pkg-config --libs --cflags glib-2.0)
      CC=gcc $(INCLUDES)
      PROJECT=re

      # Targets
      full: clean compile

      clean:
      rm $(PROJECT)

      compile:
      $(CC) $(PROJECT).c -o $(PROJECT)


      .c code being compiled:



      #include <glib.h>    

      void print_upppercase_words(const gchar *string)
      {
      /* Print all uppercase-only words. */

      GRegex *regex;
      GMatchInfo *match_info;

      regex = g_regex_new("[A-Z]+", 0, 0, NULL);
      g_regex_match(regex, string, 0, &match_info);

      while (g_match_info_matches(match_info))
      {
      gchar *word = g_match_info_fetch(match_info, 0);
      g_print("Found %sn", word);
      g_free(word);
      g_match_info_next(match_info, NULL);
      }

      g_match_info_free(match_info);
      g_regex_unref(regex);
      }

      int main()
      {
      gchar *string = "My body is a cage. My mind is THE key.";

      print_uppercase_words(string);
      }


      Strangely, when I run glib-config it doesn't like that command -- though I don't know how to tell bash or make how to just use one over the other when it complains that gdlib-config is in these 2 packages.



      $> glib-config
      No command 'glib-config' found, did you mean:
      Command 'gdlib-config' from package 'libgd2-xpm-dev' (main)
      Command 'gdlib-config' from package 'libgd2-noxpm-dev' (main)
      glib-config: command not found









      share|improve this question















      I'm having trouble compiling a simple, sample program against glib on Ubunutu. I get these errors. I can get it to compile but not link with the -c flag. Which I believe means I have the glib headers installed, but it's not finding the shared object code. See also the make file below.



      $> make re
      gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 re.c -o re
      /tmp/ccxas1nI.o: In function `print_uppercase_words':
      re.c:(.text+0x21): undefined reference to `g_regex_new'
      re.c:(.text+0x41): undefined reference to `g_regex_match'
      re.c:(.text+0x54): undefined reference to `g_match_info_fetch'
      re.c:(.text+0x6e): undefined reference to `g_print'
      re.c:(.text+0x7a): undefined reference to `g_free'
      re.c:(.text+0x8b): undefined reference to `g_match_info_next'
      re.c:(.text+0x97): undefined reference to `g_match_info_matches'
      re.c:(.text+0xa7): undefined reference to `g_match_info_free'
      re.c:(.text+0xb3): undefined reference to `g_regex_unref'
      collect2: ld returned 1 exit status
      make: *** [re] Error 1


      Makefile used:



      # Need to installed libglib2.0-dev some system specific install that will
      # provide a value for pkg-config
      INCLUDES=$(shell pkg-config --libs --cflags glib-2.0)
      CC=gcc $(INCLUDES)
      PROJECT=re

      # Targets
      full: clean compile

      clean:
      rm $(PROJECT)

      compile:
      $(CC) $(PROJECT).c -o $(PROJECT)


      .c code being compiled:



      #include <glib.h>    

      void print_upppercase_words(const gchar *string)
      {
      /* Print all uppercase-only words. */

      GRegex *regex;
      GMatchInfo *match_info;

      regex = g_regex_new("[A-Z]+", 0, 0, NULL);
      g_regex_match(regex, string, 0, &match_info);

      while (g_match_info_matches(match_info))
      {
      gchar *word = g_match_info_fetch(match_info, 0);
      g_print("Found %sn", word);
      g_free(word);
      g_match_info_next(match_info, NULL);
      }

      g_match_info_free(match_info);
      g_regex_unref(regex);
      }

      int main()
      {
      gchar *string = "My body is a cage. My mind is THE key.";

      print_uppercase_words(string);
      }


      Strangely, when I run glib-config it doesn't like that command -- though I don't know how to tell bash or make how to just use one over the other when it complains that gdlib-config is in these 2 packages.



      $> glib-config
      No command 'glib-config' found, did you mean:
      Command 'gdlib-config' from package 'libgd2-xpm-dev' (main)
      Command 'gdlib-config' from package 'libgd2-noxpm-dev' (main)
      glib-config: command not found






      compiling linker static-linking glib






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 16 at 4:18









      Rui F Ribeiro

      38.9k1479129




      38.9k1479129










      asked Apr 1 '12 at 18:13









      lucidquiet

      689277




      689277






















          1 Answer
          1






          active

          oldest

          votes


















          2














          glib is not your problem. This is:



          re.c:(.text+0xd6): undefined reference to `print_uppercase_words'


          What it's saying is you're calling a function print_uppercase_words, but it can't find it.



          And there's a reason. Look very closely. There's a typo:



          void print_upppercase_words(const gchar *string)




          After you fix that, you might still have a problem because you are specifying the libraries before the modules that require those libraries. In short, your command should be written



          gcc -o re re.o -lglib-2.0


          so that -lglib-2.0 comes after re.o.



          So I'd write your Makefile more like this:



          re.o: re.c
          $(CC) -I<includes> -o $@ -c $^

          re: re.o
          $(CC) $^ -l<libraries> -o $@


          In fact, if you set the right variables, make will figure it all out for you automatically.



          CFLAGS=$(shell pkg-config --cflags glib-2.0)
          LDLIBS=$(shell pkg-config --libs glib-2.0)
          CC=gcc

          re: re.o





          share|improve this answer























          • Uh -- damn. I fixed the typo and I still have the errors found in what used to be print_upppercase_words (now with only 1 'p'). The reported error as an undefined reference to that function is now gone, but the glib linking errors are still present.
            – lucidquiet
            Apr 1 '12 at 18:41












          • See my update. My guess is that you need to put the -lglib-2.0 after re.c or re.o.
            – Mikel
            Apr 1 '12 at 19:05











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f35487%2flinker-errors-when-compiling-against-glib%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          glib is not your problem. This is:



          re.c:(.text+0xd6): undefined reference to `print_uppercase_words'


          What it's saying is you're calling a function print_uppercase_words, but it can't find it.



          And there's a reason. Look very closely. There's a typo:



          void print_upppercase_words(const gchar *string)




          After you fix that, you might still have a problem because you are specifying the libraries before the modules that require those libraries. In short, your command should be written



          gcc -o re re.o -lglib-2.0


          so that -lglib-2.0 comes after re.o.



          So I'd write your Makefile more like this:



          re.o: re.c
          $(CC) -I<includes> -o $@ -c $^

          re: re.o
          $(CC) $^ -l<libraries> -o $@


          In fact, if you set the right variables, make will figure it all out for you automatically.



          CFLAGS=$(shell pkg-config --cflags glib-2.0)
          LDLIBS=$(shell pkg-config --libs glib-2.0)
          CC=gcc

          re: re.o





          share|improve this answer























          • Uh -- damn. I fixed the typo and I still have the errors found in what used to be print_upppercase_words (now with only 1 'p'). The reported error as an undefined reference to that function is now gone, but the glib linking errors are still present.
            – lucidquiet
            Apr 1 '12 at 18:41












          • See my update. My guess is that you need to put the -lglib-2.0 after re.c or re.o.
            – Mikel
            Apr 1 '12 at 19:05
















          2














          glib is not your problem. This is:



          re.c:(.text+0xd6): undefined reference to `print_uppercase_words'


          What it's saying is you're calling a function print_uppercase_words, but it can't find it.



          And there's a reason. Look very closely. There's a typo:



          void print_upppercase_words(const gchar *string)




          After you fix that, you might still have a problem because you are specifying the libraries before the modules that require those libraries. In short, your command should be written



          gcc -o re re.o -lglib-2.0


          so that -lglib-2.0 comes after re.o.



          So I'd write your Makefile more like this:



          re.o: re.c
          $(CC) -I<includes> -o $@ -c $^

          re: re.o
          $(CC) $^ -l<libraries> -o $@


          In fact, if you set the right variables, make will figure it all out for you automatically.



          CFLAGS=$(shell pkg-config --cflags glib-2.0)
          LDLIBS=$(shell pkg-config --libs glib-2.0)
          CC=gcc

          re: re.o





          share|improve this answer























          • Uh -- damn. I fixed the typo and I still have the errors found in what used to be print_upppercase_words (now with only 1 'p'). The reported error as an undefined reference to that function is now gone, but the glib linking errors are still present.
            – lucidquiet
            Apr 1 '12 at 18:41












          • See my update. My guess is that you need to put the -lglib-2.0 after re.c or re.o.
            – Mikel
            Apr 1 '12 at 19:05














          2












          2








          2






          glib is not your problem. This is:



          re.c:(.text+0xd6): undefined reference to `print_uppercase_words'


          What it's saying is you're calling a function print_uppercase_words, but it can't find it.



          And there's a reason. Look very closely. There's a typo:



          void print_upppercase_words(const gchar *string)




          After you fix that, you might still have a problem because you are specifying the libraries before the modules that require those libraries. In short, your command should be written



          gcc -o re re.o -lglib-2.0


          so that -lglib-2.0 comes after re.o.



          So I'd write your Makefile more like this:



          re.o: re.c
          $(CC) -I<includes> -o $@ -c $^

          re: re.o
          $(CC) $^ -l<libraries> -o $@


          In fact, if you set the right variables, make will figure it all out for you automatically.



          CFLAGS=$(shell pkg-config --cflags glib-2.0)
          LDLIBS=$(shell pkg-config --libs glib-2.0)
          CC=gcc

          re: re.o





          share|improve this answer














          glib is not your problem. This is:



          re.c:(.text+0xd6): undefined reference to `print_uppercase_words'


          What it's saying is you're calling a function print_uppercase_words, but it can't find it.



          And there's a reason. Look very closely. There's a typo:



          void print_upppercase_words(const gchar *string)




          After you fix that, you might still have a problem because you are specifying the libraries before the modules that require those libraries. In short, your command should be written



          gcc -o re re.o -lglib-2.0


          so that -lglib-2.0 comes after re.o.



          So I'd write your Makefile more like this:



          re.o: re.c
          $(CC) -I<includes> -o $@ -c $^

          re: re.o
          $(CC) $^ -l<libraries> -o $@


          In fact, if you set the right variables, make will figure it all out for you automatically.



          CFLAGS=$(shell pkg-config --cflags glib-2.0)
          LDLIBS=$(shell pkg-config --libs glib-2.0)
          CC=gcc

          re: re.o






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 1 '12 at 19:05

























          answered Apr 1 '12 at 18:32









          Mikel

          38.9k1099125




          38.9k1099125












          • Uh -- damn. I fixed the typo and I still have the errors found in what used to be print_upppercase_words (now with only 1 'p'). The reported error as an undefined reference to that function is now gone, but the glib linking errors are still present.
            – lucidquiet
            Apr 1 '12 at 18:41












          • See my update. My guess is that you need to put the -lglib-2.0 after re.c or re.o.
            – Mikel
            Apr 1 '12 at 19:05


















          • Uh -- damn. I fixed the typo and I still have the errors found in what used to be print_upppercase_words (now with only 1 'p'). The reported error as an undefined reference to that function is now gone, but the glib linking errors are still present.
            – lucidquiet
            Apr 1 '12 at 18:41












          • See my update. My guess is that you need to put the -lglib-2.0 after re.c or re.o.
            – Mikel
            Apr 1 '12 at 19:05
















          Uh -- damn. I fixed the typo and I still have the errors found in what used to be print_upppercase_words (now with only 1 'p'). The reported error as an undefined reference to that function is now gone, but the glib linking errors are still present.
          – lucidquiet
          Apr 1 '12 at 18:41






          Uh -- damn. I fixed the typo and I still have the errors found in what used to be print_upppercase_words (now with only 1 'p'). The reported error as an undefined reference to that function is now gone, but the glib linking errors are still present.
          – lucidquiet
          Apr 1 '12 at 18:41














          See my update. My guess is that you need to put the -lglib-2.0 after re.c or re.o.
          – Mikel
          Apr 1 '12 at 19:05




          See my update. My guess is that you need to put the -lglib-2.0 after re.c or re.o.
          – Mikel
          Apr 1 '12 at 19:05


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f35487%2flinker-errors-when-compiling-against-glib%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre