OpenCV 2.3 doesn't compile, undefined reference error - c++

I'm using OpenCV in Windows 7 64bits and Netbeans 7.0. I tried to compile the next code using MinGW and cygwin but both fails with undefined references.
When I use MAT or FLANN and others I can't compile, but I'm adding all libraries (I tried only adding Debug ones, Release ones, only needed ones... but fails).
The same code in ubuntu works, but I need to compile it in windows too. I'm using the 2.3 compiled version (using CMake) and the installable one.
#include "opencv2\opencv.hpp"
#include <iostream>
using namespace std;
int main(void)
{
cv::Mat::eye(1, 1, 0);
return 0;
}
"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
rm -f -r build/Release
rm -f dist/Release/Cygwin-Windows/opencv23sandbox.exe
make[1]: Leaving directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
CLEAN SUCCESSFUL (total time: 1s)
"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
"/usr/bin/make" -f nbproject/Makefile-Release.mk dist/Release/Cygwin-Windows/opencv23sandbox.exe
make[2]: Entering directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
mkdir -p build/Release/Cygwin-Windows
rm -f build/Release/Cygwin-Windows/main.o.d
g++.exe -c -O2 -I/cygdrive/C/OpenCV2.3/build/include -MMD -MP -MF build/Release/Cygwin-Windows/main.o.d -o build/Release/Cygwin-Windows/main.o main.cpp
mkdir -p dist/Release/Cygwin-Windows
g++.exe -o dist/Release/Cygwin-Windows/opencv23sandbox build/Release/Cygwin-Windows/main.o -L/cygdrive/C/OpenCV2.3/build/x86/vc10/lib -lopencv_calib3d230 -lopencv_calib3d230d -lopencv_contrib230 -lopencv_contrib230d -lopencv_core230 -lopencv_core230d -lopencv_features2d230 -lopencv_features2d230d -lopencv_flann230 -lopencv_flann230d -lopencv_gpu230 -lopencv_gpu230d -lopencv_haartraining_engine -lopencv_haartraining_engined -lopencv_highgui230 -lopencv_highgui230d -lopencv_imgproc230 -lopencv_imgproc230d -lopencv_legacy230 -lopencv_legacy230d -lopencv_ml230 -lopencv_ml230d -lopencv_objdetect230 -lopencv_objdetect230d -lopencv_video230 -lopencv_video230d
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0xac): undefined reference to `cv::Mat::eye(int, int, int)'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x106): undefined reference to `cv::fastFree(void*)'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x16f): undefined reference to `cv::fastFree(void*)'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x1dd): undefined reference to `cv::fastFree(void*)'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x1fa): undefined reference to `cv::Mat::deallocate()'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x20a): undefined reference to `cv::Mat::deallocate()'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x21a): undefined reference to `cv::Mat::deallocate()'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x66): undefined reference to `cv::Mat::deallocate()'
build/Release/Cygwin-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x5e): undefined reference to `cv::fastFree(void*)'
collect2: ld returned 1make[2]: Leaving directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
make[1]: Leaving directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox'
exit status
make[2]: *** [dist/Release/Cygwin-Windows/opencv23sandbox.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
Trying with MinGW libs:
"/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory `/f/Proyectos/C++/OpenCV23Sandbox'
rm -f -r build/Release
rm -f dist/Release/MinGW-Windows/opencv23sandbox.exe
make[1]: Leaving directory `/f/Proyectos/C++/OpenCV23Sandbox'
CLEAN SUCCESSFUL (total time: 350ms)
"/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/f/Proyectos/C++/OpenCV23Sandbox'
"/bin/make" -f nbproject/Makefile-Release.mk dist/Release/MinGW-Windows/opencv23sandbox.exe
make[2]: Entering directory `/f/Proyectos/C++/OpenCV23Sandbox'
mkdir -p build/Release/MinGW-Windows
rm -f build/Release/MinGW-Windows/main.o.d
g++.exe -c -O2 -I/C/OpenCV2.3/build/include -MMD -MP -MF build/Release/MinGW-Windows/main.o.d -o build/Release/MinGW-Windows/main.o main.cpp
mkdir -p dist/Release/MinGW-Windows
g++.exe -o dist/Release/MinGW-Windows/opencv23sandbox build/Release/MinGW-Windows/main.o -L../OpenCV/OpenCV2.3/build/x86/mingw/lib ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_calib3d230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_contrib230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_core230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_features2d230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_flann230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_gpu230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_highgui230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_imgproc230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_legacy230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_ml230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_objdetect230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_video230.dll.a
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x4f): undefined reference to `cv::Mat::eye(int, int, int)'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0xac): undefined reference to `cv::fastFree(void*)'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x11a): undefined reference to `cv::fastFree(void*)'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x191): undefined reference to `cv::fastFree(void*)'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x1a7): undefined reference to `cv::Mat::deallocate()'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x1ba): undefined reference to `cv::Mat::deallocate()'
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x1ce): undefined reference to `cv::Mat::deallocate()'
build/Release/MinGW-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x74): undefined reference to `cv::Mat::deallocate()'
build/Release/MinGW-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x63): undefined reference to `cv::fastFree(void*)'
collect2: ld returned 1 exit status
make[2]: Leaving directory `/f/Proyectos/C++/OpenCV23Sandbox'
make[1]: Leaving directory `/f/Proyectos/C++/OpenCV23Sandbox'
make[2]: *** [dist/Release/MinGW-Windows/opencv23sandbox.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
or
g++.exe -o dist/Release/MinGW-Windows/opencv23sandbox build/Release/MinGW-Windows/main.o -L../OpenCV/OpenCV2.3/build/x86/mingw/lib -lopencv_calib3d230.dll -lopencv_contrib230.dll -lopencv_core230.dll -lopencv_features2d230.dll -lopencv_flann230.dll -lopencv_gpu230.dll -lopencv_highgui230.dll -lopencv_imgproc230.dll -lopencv_legacy230.dll -lopencv_ml230.dll -lopencv_objdetect230.dll -lopencv_video230.dll
same result.

Are you using the precompiled MinGW libraries? (it appears so). I tried for a couple of days to get my project to link successfully under Code::Blocks. I was seeing the same sort of errors you describe (bad references, etc).
I finally recompiled OpenCV using the steps shown here, and all became well.

I guess the Problem is that the library path points to the vc10 directory (-L/cygdrive/C/OpenCV2.3/build/x86/vc10/lib) instead of the mingw directory (-L/cygdrive/C/OpenCV2.3/build/x86/mingw/lib). The ld-linker can't find the methods because they are mangled for the vc++ "link.exe".
If you use 64 bit, then you have also link against 64-bit libs:
-L/cygdrive/C/OpenCV2.3/build/x64/mingw/lib.

I have exactly the same issue. I am trying to compile my program under a 64-bit Windows 7 machine with MinGW. Here is several possibilities that may result in the problem:
1) You need to make sure OpenCV2.3/build/x64/mingw/lib is link. Be careful, don't link the project to the libs for visual studio or libs for x86.
2) Make sure the proper dlls are copied to the project directory, or have been added to PATH. For example, if you use this lib libopencv_core243.dll.a, you should make sure libopencv_core243.dll can be loaded by the project. This is not the cause of the problem. But I think it is also important to know.
3) Make sure the MinGW can compile x64 programs. This is what I use: mingw-w64 (But since mingw-w64 project is moving to mingw-w64.org it's better to use the new website). Unfortunately, the one that download from MinGW32 won't work. And the link from the official site of MinGW will bring you to a second one (MinGW32).
4) By default, MinGw may compile your project to a 32 bit program. In order to make sure it compiles for 64 bit, add this compile flag -m64. Otherwise, if you only link the project with all the 64-bit libs, it will result in the problem as well.

Related

C++ application failing to build with 'cannot find -lmysqlpp' but it appears to be there

I'm trying to build an application with Netbeans and getting the following error:
/usr/bin/ld: cannot find -lmysqlpp
I believe this exists as per the below screen shots;
and here in my includes from Netbeans;
The below is the full output from Netbeans;
cd '/media/psf/DL/DL_src/FEC_src/docugirl'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/media/psf/DL/DL_src/FEC_src/docugirl'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk /app/bin/docugirl
make[2]: Entering directory '/media/psf/DL/DL_src/FEC_src/docugirl'
mkdir -p /app/bin
g++ -o /app/bin/docugirl build/Debug/GNU-Linux/docugirl.o -lm -lpthread /pcli/library/libcore.a /pcli/library/libsdd.a -lmysqlpp
/usr/bin/ld: cannot find -lmysqlpp
collect2: error: ld returned 1 exit status
make[2]: *** [nbproject/Makefile-Debug.mk:67: /app/bin/docugirl] Error 1
make[2]: Leaving directory '/media/psf/DL/DL_src/FEC_src/docugirl'
make[1]: *** [nbproject/Makefile-Debug.mk:59: .build-conf] Error 2
make[1]: Leaving directory '/media/psf/DL/DL_src/FEC_src/docugirl'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2
BUILD FAILED (exit value 2, total time: 472ms)
For completeness, the source exists on a remote Debian server (as has previous successfully created and built mysql type applications).
So, I'm a little confused, I thought and assumed that I had the necessary mysql stuff in order to build this, I am able to build other mysql applications with this setup. Is this mysqlpp different/additional to the /usr/include/mysql and /usr/include/mysql++?
The /usr/include/mysql links to /usr/include/mariadb
Any help would be greatly appreciated here, thanks in advance...
#HEKTO This was indeed the problem but it seemed that the current release of Debian (10.5) did not include the libmysql++-dev package, the reasons for which are as yet unknown to me and although I had copied the mysql++ header files across, the libmysqlpp.so was indeed not there. In this instance, I resorted to using a previous release, although I believe the next release will include this.
See here: https://packages.debian.org/stretch/libmysql++-dev

Undefined reference to sf::

I wanted to make gui apps in c++ and found SFML to be a good choice. Fortunately i am on linux so SFML(2.4) was already installed on my system.
So i started searching for some tutorials and found one that makes a simple window. But when i run the code i get an error saying undefined reference to sf::(function i am using). Here's the code
#include <SFML/Graphics.hpp>
int main(void)
{
sf::RenderWindow window(sf::VideoMode(640,480),"SFML working");
return 0;
}
And here's the error log.
cd '/home/jasper/NetBeansProjects/SFML'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/jasper/NetBeansProjects/SFML'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/sfml
make[2]: Entering directory '/home/jasper/NetBeansProjects/SFML'
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/sfml build/Debug/GNU-Linux/main.o
build/Debug/GNU-Linux/main.o: In function `main':
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::String::String(char const*, std::locale const&)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::RenderWindow::~RenderWindow()'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/GNU-Linux/sfml' failed
make[2]: *** [dist/Debug/GNU-Linux/sfml] Error 1
make[2]: Leaving directory '/home/jasper/NetBeansProjects/SFML'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/jasper/NetBeansProjects/SFML'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 172ms)
I've tried searching for solution on google but couldn't find any effective one. So i thought some expert opinion would be good. Help please. Thanks
You forgot to link with SFML libraries. Those are at least:
sfml-graphics
sfml-window
sfml-system
As the documentation explains, on Linux it can be done like this:
g++ myapp.o -o myapp -lsfml-graphics -lsfml-window -lsfml-system
Or if using an IDE, specify them as Additional Dependencies in Linker settings.

C++ boost error

I'm building a code based on this fast factorial library, and it depends on boost and mpir. I'm running Ubuntu 14.04 and using Netbeans 8.0.2. To simply test the #include statements of the library I made this silly code:
#include <iostream>
#include <mpir.h>
#include <primeswing.h>
#include <xmath.h>
/*
*
*/
int main() {
long x = 4;
std::cout << x;
return 0;
}
When I try to compile it however I get the following error
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/arengorn/NetBeansProjects/BA'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/ba
make[2]: Entering directory `/home/arengorn/NetBeansProjects/BA'
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/ba build/Debug/GNU-Linux-x86/main.o ->lm
build/Debug/GNU-Linux-x86/main.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/ba] Error 1
make[2]: Leaving directory `/home/arengorn/NetBeansProjects/BA'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/arengorn/NetBeansProjects/BA'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 114ms)
Can anyone help me with why is the boost library (which is installed and present under /usr/include) is not working?
As commented by Wintermute
You need to link libboost_system.so. Put -lboost_system in your linker flags.
That solved the problem.

C++ Boost on linux via Netbeans remote developement: undefined reference to boost::filesystem::path::codecvt()

So I installed Netbeans on windows7 and configured the Ubuntu box with samba to share the developement directory where I have the sources and the boost library.
I compiled the boost library to be able to link to boost_filesystem but I still get this error when I try to compile the application:
Copying project files to /home/nms/.netbeans/remote/ophelia.tele2.net/t2003915-Windows-x86_64/ at nms#ophelia.tele2.net
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/nms/.netbeans/remote/ophelia.tele2.net/t2003915-Windows-x86_64/Z/mr_deamon'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/mr_deamon
make[2]: Entering directory `/home/nms/.netbeans/remote/ophelia.tele2.net/t2003915- Windows-x86_64/Z/mr_deamon'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/mr_deamon.o.d"
g++ -c -g -I/opt/mail-relay/mr_deamon/boost_1_55_0 -I/opt/mail-relay/mr_deamon/mysql_connector_cpp/include -MMD -MP -MF "build/Debug/GNU-Linux-x86/mr_deamon.o.d" -o build/Debug/GNU-Linux-x86/mr_deamon.o mr_deamon.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/mr_deamon build/Debug/GNU-Linux-x86/mr_deamon.o -L/opt/mail-relay/mr_deamon/mysql_connector_cpp/lib -L/opt/mail-relay/mr_deamon/boost_1_55_0/bin.v2/libs -lmysqlcppconn-static -lmysqlclient -lboost_system -lboost_filesystem
build/Debug/GNU-Linux-x86/mr_deamon.o: In function `boost::filesystem::file_size(boost::filesystem::path const&)':
/opt/mail-relay/mr_deamon/boost_1_55_0/boost/filesystem/operations.hpp:447: undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)'
build/Debug/GNU-Linux-x86/mr_deamon.o: In function `path<char*>':
/opt/mail-relay/mr_deamon/boost_1_55_0/boost/filesystem/path.hpp:139: undefined reference to `boost::filesystem::path::codecvt()'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/mr_deamon] Error 1
make[2]: Leaving directory `/home/nms/.netbeans/remote/ophelia.tele2.net/t2003915-Windows-x86_64/Z/mr_deamon'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/nms/.netbeans/remote/ophelia.tele2.net/t2003915-Windows-x86_64/Z/mr_deamon'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
I thought I got the linking right.
Here is the program code:
#include <iostream>
#include <boost/filesystem.hpp>
//using namespace std;
using namespace boost::filesystem;
int main(int argc, char**argv)
{
std::cout << file_size(argv[0]);
return EXIT_SUCCESS;
}
The sql part works fine with linking and all, but only including the boost filesystem is enough to get a build error, can't get how to use remote developement with netbeans on windows to Linux. What am I doing wrong?
A new try without netbeans, just on Ubuntu with the example from Boost filesystem link ...
and with compile command:
g++ -pthread mr.cpp -lboost_filesystem-mt -lboost_system-mt
the output is
/tmp/ccIZaqeX.o: In function boost::filesystem::file_size(boost::filesystem::path const&)':
mr.cpp: (.text._ZN5boost10filesystem9file_sizeERKNS0_4pathE[boost::filesystem::file_size(boost::filesystem::path const&)]+0x19): undefined reference toboost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)'
/tmp/ccIZaqeX.o: In function boost::filesystem::path::path<char*>(char* const&, boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<char*>::type>, void>::type*)':
mr.cpp: (.text._ZN5boost10filesystem4pathC2IPcEERKT_PNS_9enable_ifINS0_11path_traits11is_pathableINS_5decayIS4_E4typeEEEvE4typeE[_ZN5boost10filesystem4pathC5IPcEERKT_PNS_9enable_ifINS0_11path_traits11is_pathableINS_5decayIS4_E4typeEEEvE4typeE]+0x22): undefined reference toboost::filesystem::path::codecvt()'
collect2: ld returned 1 exit status
I don't get it..
I got the same problem just yesterday:
How I solved:
First: if you installed Boost by source, make sure you are compiling it to right compiler toolset that you are using at netbeans. For instance, I tested it with MinGW # Windows 8 Boost/MingW.
Second: In Netbeans (I used 7.4 version), I added the libraries I want by hand:
Project Properties > Linker > Libraries > Add Library > Select the .a
files.
EDIT:
This link maybe be useful: undefined reference with boost when I try to compile
Great, so finally it worked, here is what I did:
1- Installed gcc 4.8 (not sure if this is relevant).
2- downloaded and unpacked boost into /usr/local
3- ran bootstrap.sh
4- modify toolset parameter in project-config.jam into using gcc : 4.8.1 : g++-4.8 ;
5- run ./b2 --with-system
6- run ./b2 --with-filesystem
both step 5 and 6 are done with user root.
7- compile the source file like this:
# g++-4.8 mr.cpp -L /usr/local/boost_1_55_0/stage/lib -I /usr/local/boost_1_55_0 -lboost_system -lboost_filesystem -o mr
Jee, finally, I was few minutes from quitting Boost.
What I think made a difference is the consistency of the compiler (toolset) and the install path, and specially those two "-L /usr/local/boost_1_55_0/stage/lib -I /usr/local/boost_1_55_0"

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
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.