undefined-reference

C - Undefined reference to function error with linked files

笑着哭i 提交于 2021-02-18 18:09:30
问题 I started implementing a large program. But I ran into a massive issue. So here is very simplified code of my program. I have a separate .c file for my functions which is normal.c the main program is main.c and I have linked those two with cal.h header file. main.c #include <stdio.h> #include "cal.h" void main() { int num1, num2, ans; num1=5; num2=5; ans=add(num1, num2); printf("%d" ,ans); } normal.c #include "cal.h" int add(int num1, int num2) { return num1+num2; } cal.h #ifndef CAL_H

C error: “Undefined reference to 'sf_open'” from libsndfile

非 Y 不嫁゛ 提交于 2021-02-17 06:29:42
问题 I am using Code::Blocks to test some codes, and I just can't biuld this code: #include <stdio.h> #include <stdlib.h> #include <sndfile.h> int main() { SNDFILE *sf; sf = sf_open("file.wav",SFM_READ,&info); //error happens in this line ... And the error is "undefined reference to `sf_open'", this not only happens to sf_open but also to any function from sndfile.h. Actually here is what I did to get here: I've first downloaded and installed libsndfile for Windows x64 (I'm using Windows 10) from

CMake - Undefined Reference

不问归期 提交于 2021-02-10 06:42:46
问题 I am trying to include gtest to my project. The problem is that I get a undefined reference error in the GTest. I am trying to test the Node class in Gtest. Inside the constructor of the Node I am using the Class Logger. Although I have added the library logger to the gtest-target I still the undefined reference error regarding to the Logger.... My guess CMake does no look for nested classes that are used inside Node. only Node itself. Temperoy fix If I use the Logger in the gtest-node.cpp it

perl xs module writing - Use another function from within same xs file

烂漫一生 提交于 2021-02-09 11:00:40
问题 I'm a beginner in XS and have spent some time looking for this answer on the web with no luck. The problem is that XS changes the name of the function and when it goes to compile, I will get an undefined reference error. For example consider the XS code below: size_t matrixIndex (colIndex, rowIndex,nCols,nRows) size_t colIndex size_t rowIndex size_t nCols size_t nRows CODE: size_t register i; RETVAL = (rowIndex * nCols) + colIndex; OUTPUT: RETVAL I then try to use this in the following

Undefined reference to CryptoPP::AlignedAllocate(unsigned int)

泪湿孤枕 提交于 2021-02-08 13:15:22
问题 I am using crypto++ in c++ linux. Here is my simple code: #include <iostream> #include <fstream> #include <string.h> #include "crypto++/cryptlib.h" #include "crypto++/modes.h" #include "crypto++/filters.h" #include "crypto++/aes.h" #include "crypto++/osrng.h" #include "crypto++/strciphr.h" using namespace std; using namespace CryptoPP; ifstream::pos_type size; char * memblock; int length; char * _iv[AES::BLOCKSIZE]; char * keys[AES::MAX_KEYLENGTH]; void encriptCTR(byte * outbyte, const byte *

“undefined reference to symbol” error when using `ld` to link

烈酒焚心 提交于 2021-02-04 18:48:49
问题 I am new to writing programs on Linux. I have a single module program that uses shm_open , ftruncate , mmap , fork , and wait . I compiled this program with gcc -c and then linked it with ld -lrt (librt is needed for shm_open ) and I got a strange linker error: undefined reference to symbol 'waitpid@@GLIBC_2.2.5' The manpage for wait says Feature Test Macro Requirements for glibc (see feature_test_macros(7)): waitid(): Since glibc 2.26: _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200809L Glibc

Create shared library with undefined reference using gcc, Unix/Windows differences

扶醉桌前 提交于 2021-01-29 21:13:25
问题 I want to build a simple library with some undefined reference, as you can see in function_two.c , I call three() which is not defined. header.h void one(); void two(); void three(); function_one.c #include <stdio.h> #include "header.h" void one() { printf("one\n"); } function_two.c #include <stdio.h> #include "header.h" void two() { printf("two\n"); three(); } Using Linux , I compile both files and then I link them linux:~/example$ gcc -c -Wall -Werror -fpic function_one.c linux:~/example$

undefined reference to > `std::ostream::operator<<(unsigned long)'

时间秒杀一切 提交于 2021-01-29 08:53:01
问题 I have the following code: #include <sstream> using namespace std; int main () { ostringstream oss; unsigned long k = 5; oss << k; } Compiled with the following parameters: /usr/local/gcc-10.2.0/bin/g++ -I/usr/local/gcc-10.2.0/include -L/usr/local/gcc-10.2.0/lib64 -Wl,-rpath,/usr/local/gcc-10.2.0/lib64 -lstdc++ b.cpp Got the following output: /tmp/cclRSXGV.o: In function main': b.cpp:(.text+0x35): undefined reference to std::ostream::operator<<(unsigned long)' collect2: error: ld returned 1

Why can templates only be implemented in the header file?

陌路散爱 提交于 2021-01-29 07:52:58
问题 Quote from The C++ standard library: a tutorial and handbook: The only portable way of using templates at the moment is to implement them in header files by using inline functions. Why is this? (Clarification: header files are not the only portable solution. But they are the most convenient portable solution.) 回答1: Caveat: It is not necessary to put the implementation in the header file, see the alternative solution at the end of this answer. Anyway, the reason your code is failing is that,

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

给你一囗甜甜゛ 提交于 2021-01-29 05:26:03
问题 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