우분투에서 간단한 예제 프로그램을 컴파일하는 데 문제가 있습니다. 다음과 같은 오류가 발생합니다. 컴파일 할 수 있지만 -c
플래그로 연결되지는 않습니다.이 플래그는 glib 헤더가 설치되어 있다고 믿습니다.하지만 공유 객체 코드를 찾지 못했습니다. 아래 Make 파일을 참조하십시오.glib에서 컴파일 할 때 링커 오류가 발생합니다 ...?
$> 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
코드는 컴파일되는 : 나는 glib-config
을 실행할 때
#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);
}
이상하게도, 그것은 그 명령을 좋아하지 않는다, 나도 몰라하지만이이 두 패키지에 있다고 불평 할 때 Bash에게 말하는 방법 또는 다른 것을 사용하는 방법을 만드십시오. 컴파일러 명령의 끝에
$> 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
그래서 해결책은 무엇입니까, 이해가 안되나요? – user3728501