I am new to c++ and I have the following problem:
files: - main.cpp - utils.h - utils.cpp
When I am doing:
g++ -c -std=c++11 utils.cpp (compiles) g++ -c -std=c++11 main.cpp (compiles)
when I try to link:
g++ -o main.o utils.o
/usr/lib/gcc/i686-redhat-linux/4.8.3/../../../crt1.o: In function
_start': (.text+0x18): undefined reference to
main' utils.o: In functionclean_html(std::string const&)': utils.cpp:(.text+0xfa): undefined reference to
tidyCreate' utils.cpp:(.text+0x118): undefined reference totidyOptSetBool' utils.cpp:(.text+0x13b): undefined reference to
tidyOptSetBool' utils.cpp:(.text+0x15e): undefined reference totidyOptSetBool' utils.cpp:(.text+0x181): undefined reference to
tidyOptSetBool' utils.cpp:(.text+0x1a4): undefined reference totidyOptSetBool' utils.cpp:(.text+0x1c7): undefined reference to
tidyOptSetValue' utils.cpp:(.text+0x1ea): undefined reference totidyOptSetValue' utils.cpp:(.text+0x209): undefined reference to
tidyOptSetBool' utils.cpp:(.text+0x228): undefined reference totidyOptSetBool' utils.cpp:(.text+0x247): undefined reference to
tidyOptSetInt' utils.cpp:(.text+0x281): undefined reference totidyParseString' utils.cpp:(.text+0x295): undefined reference to
tidyCleanAndRepair' utils.cpp:(.text+0x2b0): undefined reference totidySaveBuffer' utils.cpp:(.text+0x322): undefined reference to
tidyBufFree' utils.cpp:(.text+0x32d): undefined reference to `tidyRelease' collect2: error: ld returned 1 exit status
In utils.cpp I have a function clean_html. When I remove this function the code is linked with success.
I am using gcc version 4.8.3 20140911 (Red Hat 4.8.3-7) (GCC) .
Tidy is installed via fedora repos using: Package libtidy-devel-0.99.0-28.20091203.fc19.i686 already installed and latest version Package libtidy-0.99.0-28.20091203.fc19.i686 already installed and latest version
Edit:
Forgot to mention: - I include tidy.h using #include
tidy.h is at /usr/include/tidy.h
-ltidy
on linking stage. – πάντα ῥεῖ-l
option to link the tidy library. – geert3/usr/lib/libtidy.so
, so you would needg++ -ltidy -o main.o utils.o
. – geert3