2012-04-01 15 views
8

मुझे उबंटू पर ग्लिब के खिलाफ एक सरल, नमूना कार्यक्रम संकलित करने में समस्या हो रही है। मुझे निम्नलिखित त्रुटियां मिलती हैं I मैं इसे संकलित करने के लिए प्राप्त कर सकता हूं लेकिन -c ध्वज से लिंक नहीं कर सकता, जिसका मेरा मानना ​​है कि मेरे पास ग्लिब हेडर इंस्टॉल हैं, लेकिन यह साझा ऑब्जेक्ट कोड नहीं ढूंढ रहा है। नीचे Make फ़ाइल भी देखें।ग्लिब के खिलाफ संकलन करते समय लिंकर त्रुटियां ...?

$> 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 प्रयोग किया है:

# 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 कोड संकलित किया जा रहा:

#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 %s\n", 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); 
} 

अजीब है, जब मैं glib-config चलाने के लिए, यह नहीं है कि आदेश की तरह होता है, हालांकि मैं नहीं जानता कि बैश को कैसे बताना है या किसी अन्य पर एक का उपयोग कैसे करें जब यह शिकायत करता है कि gdlib-config इन दो पैकेजों में है। संकलक आदेश के अंत में

$> 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 
+0

तो समाधान क्या था, मुझे समझ में नहीं आया? – user3728501

उत्तर

23

पुस्तकालय:

जीसीसी मैं/usr/शामिल/चिकना-2.0 मैं/usr/lib/x86_64-linux-जीएनयू/चिकना-2.0/re.c शामिल -ओ -lglib-2,0

GCC Link Options से पुन:

 
-llibrary 
-l library 
    Search the library named library when linking. 
    (The second alternative with the library as a separate argument 
    is only for POSIX compliance and is not recommended.) 

    It makes a difference where in the command you write this option; 
    the linker searches and processes libraries and object files in the 
    order they are specified. 
    Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but 
    before bar.o. If bar.o refers to functions in `z', those functions 
    may not be loaded. 
+1

इसे सिंगल-पास लिंकिंग कहा जाता है: https://computation.llnl.gov/casc/components/docs/users_guide/node319.html –

+0

ठीक है, मैंने पढ़ा है कि इस समस्या का शोध करते समय, और मैंने इन सभी को आजमाया है : जीसीसी-आई/यूएसआर/शामिल/ग्लिब-2.0-आई/यूएसआर/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 re.c -o re gcc -lglib-2.0 - I/usr/include/glib-2.0-I/usr/lib/x86_64-linux-gnu/glib-2.0/re.c -o re gcc-I/usr/include/glib-2.0-I/usr शामिल करें /lib/x86_64-linux-gnu/glib-2.0/include re.c -o re -lglib-2.0 मुझे नहीं लगता कि आदेश वास्तव में कुछ भी बदल रहा है। मैंने सोचा कि -lglib-2.0 ध्वज को .so फ़ाइलों को इंगित करना चाहिए - लेकिन मुझे नहीं लगता कि यह .so फ़ाइलों को ढूंढ रहा है। – lucidquiet

+0

तो समाधान क्या था, मुझे समझ में नहीं आया? – user3728501

2
gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include re.c -o re -lglib-2.0 

उह - नरक - मैंने इतनी सारी चीजों की कोशिश की है और शायद उन्हें सब कुछ गलत मिला है, लेकिन मैंने अभी उपरोक्त कोशिश की, और यह काम किया .... soooo हल हो गया।

+0

क्या मैंने पोस्ट नहीं किया है? – hmjd

+0

यह है - यही कारण है कि मैंने आपका जवाब स्वीकार कर लिया।मुझे लगता है कि मुझे आपकी पोस्ट में अभी एक टिप्पणी जोड़नी चाहिए थी। – lucidquiet

+0

आपको स्वीकार करने के उत्तर के बगल में सफेद टिक पर क्लिक करना होगा। – hmjd

संबंधित मुद्दे