emstol
emstol

Reputation: 6206

undefined reference to `u_fopen_48'

I'm new to c/c++ and I guess I have some basic problem. I get undefined reference to u_fopen_48' error when compiling:

#include <unicode/ustdio.h>

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

Doc for this function is here. I'm using ICU 4.8.1 (compiled myself, step by step according to readme.html ;)), NetBeans with g++ underneath. If it helped this is what I see during building:

"/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

Upvotes: 2

Views: 1914

Answers (1)

immortal
immortal

Reputation: 3188

You seem to have forgotten to link the library you used. You should refer to This page for instructions.

When building composite projects the compiler can't just easily find all it's required references. Most libraries come in the form of a shared object file (.so) and without their C code to be compiled along with the rest of your project, while only supplying the headers for their functions. This allows the compiler to create "sockets" in the code for the functions to be placed into, but without telling the linker where these functions should be taken from - the link process will simply fail. You must, therefore, explicitly tell the linker where to search for the symbols it will seek, and this is usually done with the -l flag, though it would appear the ICU library has taken a somewhat different approach to it.

Upvotes: 3

Related Questions