undefined-reference

C++ templates, undefined reference

让人想犯罪 __ 提交于 2019-11-26 06:03:14
问题 I have a function declared like so: template <typename T> T read(); and defined like so: template <typename T> T packetreader::read() { offset += sizeof(T); return *(T*)(buf+offset-sizeof(T)); } However, when I try to use it in my main() function: packetreader reader; reader.read<int>(); I get the following error from g++: g++ -o main main.o packet.o main.o: In function `main\': main.cpp:(.text+0xcc): undefined reference to `int packetreader::read<int>()\' collect2: ld returned 1 exit status

DSO missing from command line [duplicate]

微笑、不失礼 提交于 2019-11-26 05:35:58
问题 This question already has an answer here: libpthread.so.0: error adding symbols: DSO missing from command line 12 answers Linking error: DSO missing from command line 4 answers I am trying to compile a C++ program like this: $ g++ -o Sniffer_Train main.cpp Sniffer_train.cpp Sniffer_train.h -lmysqlclient -lpcap However I get the following error: /usr/bin/ld: /tmp/cct6xeXD.o: undefined reference to symbol \'pthread_join@@GLIBC_2.4\' //lib/arm-linux-gnueabihf/libpthread.so.0: error adding

Undefined reference to a static member

跟風遠走 提交于 2019-11-26 04:33:04
I'm using a cross compiler. My code is: class WindowsTimer{ public: WindowsTimer(){ _frequency.QuadPart = 0ull; } private: static LARGE_INTEGER _frequency; }; I get the following error: undefined reference to `WindowsTimer::_frequency' I also tried to change it to LARGE_INTEGER _frequency.QuadPart = 0ull; or static LARGE_INTEGER _frequency.QuadPart = 0ull; but I'm still getting errors. anyone knows why? You need to define _frequency in the .cpp file. i.e. LARGE_INTEGER WindowsTimer::_frequency; Vyktor Linker doesn't know where to allocate data for _frequency and you have to tell it manually.

“undefined reference to” in G++ Cpp

心已入冬 提交于 2019-11-26 03:45:04
问题 Can\'t seem to get the errors to go away. Errors are below. I have looked on google and still can\'t figure it out. It is not like I am new to Cpp, but have not fooled with it in a while. Weird thing is it worked with G++ in Windows... Errors: [ze@fed0r! - - -** _ _*]$ g++ main.cpp /tmp/ccJL2ZHE.o: In function `main\': main.cpp:(.text+0x11): undefined reference to `Help::Help()\' main.cpp:(.text+0x1d): undefined reference to `Help::sayName()\' main.cpp:(.text+0x2e): undefined reference to

Undefined reference to `pow&#39; and `floor&#39;

走远了吗. 提交于 2019-11-26 03:22:13
问题 I\'m trying to make a simple fibonacci calculator in C but when compiling gcc tells me that I\'m missing the pow and floor functions. What\'s wrong? Code: #include <stdio.h> #include <math.h> int fibo(int n); int main() { printf(\"Fib(4) = %d\", fibo(4)); return 0; } int fibo(int n) { double phi = 1.61803399; return (int)(floor((float)(pow(phi, n) / sqrt(5)) + .5f)); } Output: gab@testvm:~/work/c/fibo$ gcc fib.c -o fibo /tmp/ccNSjm4q.o: In function `fibo\': fib.c:(.text+0x4a): undefined

libpthread.so.0: error adding symbols: DSO missing from command line

青春壹個敷衍的年華 提交于 2019-11-26 03:14:28
问题 When I\'m compiling openvswitch-1.5.0, I\'ve encountered the following compile error: gcc -Wstrict-prototypes -Wall -Wno-sign-compare -Wpointer-arith -Wdeclaration-after-statement -Wformat-security -Wswitch-enum -Wunused-parameter -Wstrict-aliasing -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -Wno-override-init -g -O2 -export-dynamic ***-lpthread*** -o utilities/ovs-dpctl utilities/ovs-dpctl.o lib/libopenvswitch

Undefined reference to `sin` [duplicate]

不想你离开。 提交于 2019-11-26 02:33:47
问题 This question already has answers here : undefined reference to sqrt (or other mathematical functions) (5 answers) Closed last year . I have the following code (stripped down to the bare basics for this question): #include<stdio.h> #include<math.h> double f1(double x) { double res = sin(x); return 0; } /* The main function */ int main(void) { return 0; } When compiling it with gcc test.c I get the following error, and I can\'t work out why: /tmp/ccOF5bis.o: In function `f1\': test2.c:(.text

Undefined reference to a static member

人走茶凉 提交于 2019-11-26 00:59:48
问题 I\'m using a cross compiler. My code is: class WindowsTimer{ public: WindowsTimer(){ _frequency.QuadPart = 0ull; } private: static LARGE_INTEGER _frequency; }; I get the following error: undefined reference to `WindowsTimer::_frequency\' I also tried to change it to LARGE_INTEGER _frequency.QuadPart = 0ull; or static LARGE_INTEGER _frequency.QuadPart = 0ull; but I\'m still getting errors. anyone knows why? 回答1: You need to define _frequency in the .cpp file. i.e. LARGE_INTEGER WindowsTimer::

What is an undefined reference/unresolved external symbol error and how do I fix it?

此生再无相见时 提交于 2019-11-25 22:09:14
问题 What are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them? Feel free to edit/add your own. 回答1: Compiling a C++ program takes place in several steps, as specified by 2.2 (credits to Keith Thompson for the reference): The precedence among the syntax rules of translation is specified by the following phases [see footnote] . Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set

Undefined reference to `pow&#39; and `floor&#39;

孤人 提交于 2019-11-25 19:08:26
I'm trying to make a simple fibonacci calculator in C but when compiling gcc tells me that I'm missing the pow and floor functions. What's wrong? Code: #include <stdio.h> #include <math.h> int fibo(int n); int main() { printf("Fib(4) = %d", fibo(4)); return 0; } int fibo(int n) { double phi = 1.61803399; return (int)(floor((float)(pow(phi, n) / sqrt(5)) + .5f)); } Output: gab@testvm:~/work/c/fibo$ gcc fib.c -o fibo /tmp/ccNSjm4q.o: In function `fibo': fib.c:(.text+0x4a): undefined reference to `pow' fib.c:(.text+0x68): undefined reference to `floor' collect2: ld returned 1 exit status Fred You