2012-02-22 100 views
2

我是新来的C/C + +,我想我有一些基本问题。编译时,我得到undefined reference to u_fopen_48'错误:未定义的引用'u_fopen_48'

#include <unicode/ustdio.h> 

int main(int argc, char** argv) { 
    UFILE* ufile = u_fopen("/home/emstol/Desktop/utf8demo.txt", "r", NULL, "utf8"); 
    return 0; 
} 

文件此功能是here。我正在使用ICU 4.8.1(根据readme.html一步一步编译我自己)),下面有g ++的NetBeans。如果这有助于我在建设过程中看到:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf 
make[1]: Entering directory `/home/emstol/NetBeansProjects/TextFairy1' 
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/textfairy1 
make[2]: Entering directory `/home/emstol/NetBeansProjects/TextFairy1' 
mkdir -p dist/Debug/GNU-Linux-x86 
g++  -o dist/Debug/GNU-Linux-x86/textfairy1 build/Debug/GNU-Linux-x86/main.o 
build/Debug/GNU-Linux-x86/main.o: In function `main': 
/home/emstol/NetBeansProjects/TextFairy1/main.cpp:4: undefined reference to `u_fopen_48' 
collect2: ld returned 1 exit status 
make[2]: *** [dist/Debug/GNU-Linux-x86/textfairy1] Error 1 
make[2]: Leaving directory `/home/emstol/NetBeansProjects/TextFairy1' 
make[1]: *** [.build-conf] Error 2 
make[1]: Leaving directory `/home/emstol/NetBeansProjects/TextFairy1' 
make: *** [.build-impl] Error 2 

回答

3

您似乎忘记了链接您使用的库。有关说明,请参阅This page

构建复合项目时,编译器不能轻易找到所需的所有引用。大多数库都以共享对象文件(.so)的形式出现,并且没有将它们的C代码与您的项目的其余部分一起编译,同时仅为它们的函数提供头文件。这允许编译器在代码中为要放入的函数创建“套接字”,但不告诉链接器应将这些函数从何处取出 - 链接过程将会失败。 因此,您必须明确告诉链接程序在哪里搜索它将要搜索的符号,这通常是用-l标志完成的,尽管看起来ICU库已经采取了与它不同的方法。

+1

正确!感谢您快速回答。为你+1。 – emstol 2012-02-22 21:11:29