undefined-reference

C++ templates, undefined reference

冷暖自知 提交于 2019-11-26 16:39:51
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 make: *** [main] Error 1 Can anyone point me into the right direction? strager You need to use the export

Undefined reference C++

大城市里の小女人 提交于 2019-11-26 14:42:37
问题 I'm trying to compile my first legit program that I'm converting from Java (I ran a test hello world type program to check my compiler and it works). There are three files: main.cpp #include <iostream> #include "skewNormal.h" using namespace std; double getSkewNormal(double, double); int main(int argc, char **argv) { cout << getSkewNormal(10.0, 0.5) << endl; } skewNormal.cpp #define _USE_MATH_DEFINES #include <iostream> #include <math.h> using namespace std; #include <skewNormal.h> double

undefined reference to `__stack_chk_fail&#39;

六眼飞鱼酱① 提交于 2019-11-26 14:16:09
问题 Getting this error while compiling C++ code: undefined reference to `__stack_chk_fail' Options already tried: added -fno-stack-protector while compiling - did not work, error persists added a dummy implementation of void __stack_chk_fail(void) in my code. Still getting the same error. Detailed Error: /u/ac/alanger/gurobi/gurobi400/linux64/lib/libgurobi_c++.a(Env.o)(.text+0x1034): In function `GRBEnv::getPar/u/ac/alanger/gurobi/gurobi400/linux64/lib/libgurobi_c++.a(Env.o)(.text+0x1034): In

“undefined reference to” in G++ Cpp

眉间皱痕 提交于 2019-11-26 13:52:23
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 `Help::~Help()' main.cpp:(.text+0x46): undefined reference to `Help::~Help()' collect2: ld returned 1 exit

How to properly link libraries with cmake?

这一生的挚爱 提交于 2019-11-26 13:03:15
问题 I can\'t get the additional libraries I am working with to link into my project properly. I am using CLion, which uses cmake to build it\'s projects. I am trying to use several libraries in conjunction with OpenGL to texture some objects. I initially built it in Visual Studio, because I couldn\'t ever figure out how to get cmake to work with Clion. However, now that the code is all working (in Visual Studio, anyways), I want to be able to use CLion for it, because that is my preferred IDE. I

crt1.o: In function `_start&#39;: - undefined reference to `main&#39; in Linux

[亡魂溺海] 提交于 2019-11-26 12:58:31
问题 I am porting an application from Solaris to Linux The object files which are linked do not have a main() defined. But compilation and linking is done properly in Solaris and executable is generated. In Linux I get this error /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start\': (.text+0x20): undefined reference to `main\' My problem is, I cannot include new .c/.o files since its a huge application and has been running for years. How can I get rid of this

undefined reference to sqrt (or other mathematical functions)

帅比萌擦擦* 提交于 2019-11-26 12:22:45
I have this simple code: max = (int) sqrt (number); and in the header I have: #include <math.h> But application still says undefined reference to sqrt . Do you see any problem here? It looks like everything should be okay. You may find that you have to link with the math libraries on whatever system you're using, something like: gcc -o myprog myprog.c -L/path/to/libs -lm ^^^ - this bit here. Including headers lets a compiler know about function declarations but it does not necessarily automatically link to the code required to perform that function. Failing that, you'll need to show us your

Undefined reference to `sin` [duplicate]

心已入冬 提交于 2019-11-26 11:43:46
This question already has an answer here: undefined reference to sqrt (or other mathematical functions) 5 answers 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+0x13): undefined reference to `sin' collect2: ld returned 1 exit status However, I've written various test programs that call

undefined reference to `__gxx_personality_sj0`

僤鯓⒐⒋嵵緔 提交于 2019-11-26 07:38:57
问题 With gcc 4.6 when trying to execute this code: #include <iostream> using namespace std; #include <bitset> int main() { //Int<> a; long long min = std::numeric_limits<int>::min(); unsigned long long max = std::numeric_limits<int>::max(); cout << \"min: \" << min << \'\\n\'; cout << \"max: \" << max << \'\\n\'; cout << (min <= max); std::bitset<64> minimal(min); cout << \"minimal: \" << minimal; return 0; } I\'m getting the following error: 1. undefined reference to __gxx_personality_sj 2.

Undefined reference to `initscr&#39; Ncurses

亡梦爱人 提交于 2019-11-26 06:44:08
问题 I\'m trying to compile my project and I use the lib ncurse. And I\'ve got some errors when compiler links files. Here is my flags line in Makefile: -W -Wall -Werror -Wextra -lncurses I\'ve included ncurses.h Some layouts : prompt$> dpkg -S curses.h libslang2-dev:amd64: /usr/include/slcurses.h libncurses5-dev: /usr/include/ncurses.h libncurses5-dev: /usr/include/curses.h prompt$> dpkg -L libncurses5-dev | grep .so /usr/lib/x86_64-linux-gnu/libncurses.so /usr/lib/x86_64-linux-gnu/libcurses.so