undefined-reference

Why does the following code show an error?

爱⌒轻易说出口 提交于 2019-12-11 08:57:56
问题 #include <stdio.h> void m(); void n() { m(); } void main() { void m() { printf("hi"); } } On compiling, an error "undefined reference to m" is shown. Which m is being referred to? 回答1: First, let me declare clearly, Nested functions are not standard C. They are supported as GCC extension. OK, now, in your code, m() is a nested function inside main() . It is having block scope for main() only. Outside main() other functions cannot see the existence of m() ,neither can call m() directly. m()

template class and free function namespace problems with implementation

人盡茶涼 提交于 2019-12-11 06:12:01
问题 I have a class defined like this (trivial includes and preprocessor wrappers, etc. are omitted, but they are there): In Matrix.h namespace matrixmanip { template<typename T> class Matrix { public: void someFunc() const; //... }; template<typename T> void Matrix<T>::someFunc() const { //... } } // namespace matrixmanip In bitTransform.h #include "Matrix.h" namespace matrixmanip { Matrix<char> bitExpand(const Matrix<char> &mat); } // namespace matrixmanip In bitTransform.cpp #include

g++ undefined reference to library symbols [duplicate]

半城伤御伤魂 提交于 2019-12-11 06:08:28
问题 This question already has answers here : Why does the order in which libraries are linked sometimes cause errors in GCC? (9 answers) Closed 2 years ago . There are linker errors to Symbols defined by SFML, but i cannot see how they occur despite that I linked the lib. I'm using make, which I currently learn and I want to build a minimalistic dev-environment with it. Give a holler if you need anymore information than the following. I'd just like to minimize the questions size. XXX@XXX ~

Undefined reference to static member of class template referenced from static instance

安稳与你 提交于 2019-12-11 04:15:24
问题 Please take a look at the following: #include <string> #include <unordered_map> template <int N> class Object; template <int N> class Thing; template <int N> class Factory { private: using FuncPtr = Object<N>*(*)(Thing<N>*); static std::unordered_map<std::string, FuncPtr> map; public: static void insertInMap (const std::string& tag, FuncPtr funcPtr) { map.emplace (tag, funcPtr); } }; template <int N> std::unordered_map<std::string, typename Factory<N>::FuncPtr> Factory<N>::map; // won't

… undefined reference to … collect2: ld returned 1 exit status [duplicate]

风格不统一 提交于 2019-12-11 03:24:49
问题 This question already has answers here : What is an undefined reference/unresolved external symbol error and how do I fix it? (32 answers) Closed 5 years ago . I'm having some errors when compiling and I can't figure out why...is my heapsort.h supposed to have an exported type? heapsort.c #include <stdio.h> // standard libraries already included in "list.h" #include <stdlib.h> #include "heap.h" #include "heapsort.h" void heapSort(int* keys, int numKeys){ heapHndl H = NULL; H = buildHeap

“Undefined reference” trying to reference an static field

 ̄綄美尐妖づ 提交于 2019-12-11 01:38:09
问题 I have this definition for my Test class: #ifndef TEST_H #define TEST_H #include <iostream> #include <cstdlib> #include <ctime> #include <fstream> class Test { public: static bool testAll(bool debug = false); private: static bool testVector2D(bool debug = false); static bool testPolygon(bool debug = false); static bool testRectangle(bool debug = false); static bool testMap(bool debug = false); static std::ofstream outStream; static std::ifstream inStream; static void prepareWriting(); static

Linking libavcodec and libavformat: Undefined references

吃可爱长大的小学妹 提交于 2019-12-10 21:07:25
问题 I am trying to compile a project I am working on that uses ffmpeg libraries. The project is written in C. The header files are appropriately included in the source code. In particular, it seems to be using libavcodec and libavformat , and these libraries are appropriately linked in the Makefile with the LDFLAGS. Here are the flags used: -lavcodec -lavformat -lswscale -lavutil Now, because the packaged libraries that come with Ubuntu were too out-of-date, I downloaded the latest source code

Can't link GLFW3: undefined references

僤鯓⒐⒋嵵緔 提交于 2019-12-10 17:13:51
问题 I realize something similar has been asked before (glfw3 compiling undefined references), but I still can't get it to work unfortunately. Any help is welcome! Below is the compiler output when running make : g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors -I/usr/local/include -c -o Main.o Main.cpp g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors -I/usr/local/include -L/usr/local/lib -lglfw3 -lGL Main.o -o modernogl Main.o: In function `main': Main.cpp:(.text+0x9): undefined

cmake undefined reference to function

泄露秘密 提交于 2019-12-10 13:19:38
问题 The project structure below is a simplified example. I tried to boil it down to the minimal amount of files to reproduce my issue. . ├── CMakeLists.txt ├── subdir1 │ ├── CMakeLists.txt │ └── subsubdir1 │ ├── CMakeLists.txt │ ├── Example.cpp │ └── Example.h └── subdir2 ├── CMakeLists.txt ├── main.cpp └── subsubdir1 ├── CMakeLists.txt ├── ExampleCreator.cpp └── ExampleCreator.h ./CMakeLists.txt cmake_minimum_required(VERSION 2.8) project(test) macro(add_sources) file (RELATIVE_PATH _relPath "$

Unsdefined reference to library class members errors from caller program

核能气质少年 提交于 2019-12-10 10:13:31
问题 Additional Questions added below, 4/11/2011 I am developing a cross-platform set of shared libraries DLLs/Sos and tester programs in C++ though I have to be able to support C. The libraries will ship as object code only, but the tester program(s) will ship with source so our customers can have example code. For this reason I am designing the libraries to be loaded at runtime, i.e. dynamic linking using dlopen()/LoadLibraryA(). I am using g++ 4.4.3-4 on Umbutu 10.04 and VC++ 2008 on Vista/64