You need to pass -library to gcc instead of library.so ,also provide library.so's location

gcc -L/path/to/library.so -o test.o -llibrary -ldl -lpthread -lm
Answer from Rahul R Dhobi on Stack Overflow
🌐
GitHub
github.com › OpenRCT2 › OpenRCT2 › issues › 293
Undefined reference to min · Issue #293 · OpenRCT2/OpenRCT2
fabien@ubuntu:~/Projets/fbourigault/OpenRCT2/build$ LANG=C make -j3 Linking C shared library openrct2.dll CMakeFiles/openrct2.dir/objects.a(window_new_campaign.c.obj): In function `window_new_campaign_mousedown': /home/fabien/Projets/fbourigault/OpenRCT2/src/window_new_campaign.c:308: undefined reference to `min' /home/fabien/Projets/fbourigault/OpenRCT2/src/window_new_campaign.c:312: undefined reference to `max' CMakeFiles/openrct2.dir/objects.a(window_finances.c.obj): In function `window_finances_marketing_invalidate': /home/fabien/Projets/fbourigault/OpenRCT2/src/window_finances.c:1170: undefined reference to `max' collect2: error: ld returned 1 exit status make[2]: *** [openrct2.dll] Error 1 make[1]: *** [CMakeFiles/openrct2.dir/all] Error 2 make: *** [all] Error 2
Discussions

Received errors about undefined reference to min
Using PIO with VSCode and the ESP8266 chip, I received a few errors while trying to compile. On line 300, it errored that min was undefined. Changing that to std::min resolved the problem. Next it ... More on github.com
🌐 github.com
1
August 29, 2021
linux - Compile error with max_min.c:(.text+0x3c): undefined reference to `max_func' - Stack Overflow
I created simple max and min func to show max value and min value from user inputs but I got below error. could you please give me any help? #include void max_func(int i, int j); ... More on stackoverflow.com
🌐 stackoverflow.com
March 1, 2017
build fails with `undefined reference to `major'`
Reload to refresh your session. ... /usr/bin/ld: qga/commands-posix.o: in function `dev_major_minor': /home/morgan/devel/qemu-xtensa-esp32/qga/commands-posix.c:656: undefined reference to `major' /usr/bin/ld: /home/morgan/devel/qemu-xtensa-esp32/qga/commands-posix.c:657: undefined reference ... More on github.com
🌐 github.com
7
February 24, 2019
compiling - Undefined reference to math functions when linking with gcc - Unix & Linux Stack Exchange
I'm getting an error when using make to install a program. The full step that it fails on with error looks like this: gcc -g -O2 -fopenmp -L/usr/lib -lcfitsio -lm -o lenstool_tab e_nfwg.o lensto... More on unix.stackexchange.com
🌐 unix.stackexchange.com
July 17, 2015
🌐
Launchpad
answers.launchpad.net › ubuntu › +source › gnome-terminal › +question › 82506
Question #82506 “max() or min() functions in stdlib.h” : Questions : gnome-terminal package : Ubuntu
As far as I'm aware, there is no max or min function in the C or GNU standard libraries. There is fmax/fmin, but since max and min are so trivial to write ...
🌐
GitHub
github.com › pkourany › I2CDEV_MPU6050 › issues › 11
Received errors about undefined reference to min · Issue #11 · pkourany/I2CDEV_MPU6050
August 29, 2021 - Using PIO with VSCode and the ESP8266 chip, I received a few errors while trying to compile. On line 300, it errored that min was undefined. Changing that to std::min resolved the problem. Next it complained that there was not a version of min that accepted a uint8_t and int, and I fixed that by casting the first param as an int.
Author   paulelong
🌐
GitHub
github.com › libusb › libusb › issues › 72
undefined reference to min on Windows with -DNOMINMAX · Issue #72 · libusb/libusb
June 3, 2015 - I expect this is expected to be defined from windows.h, but it isn't if you #define NOMINMAX which I have to on my project because of a different library. I suggest you just implement the macro yourself, something like this: #define safe_min(a, b) (((size_t)(a) < (size_t)(b)) ?
🌐
Launchpad
answers.launchpad.net › gcc-arm-embedded › +question › 269177
Question #269177 “undefined reference to MIN” : Questions : GNU Arm Embedded Toolchain
July 13, 2015 - I can confirm that the libraries were indeed compiled without the MIN (and MAX) macro's for that particular source. I am now working on a patch to include these definitions. Still being worked on. ... Thank you for point it out this bug. Our patch to fix this issue has been applied upstream. The libraries in the upcoming release should no longer have the undefined MIN symbol.
🌐
Linux Kernel
lore.kernel.org › netdev › 20220806082406.216286-1-vincent@systemli.org › T
[PATCH iproute2] ipstats: Define MIN function to fix undefined references
[PATCH iproute2] ipstats: Define MIN function to fix undefined references @ 2022-08-06 8:24 Nick Hainke 2022-08-17 2:03 ` Stephen Hemminger 0 siblings, 1 reply; 2+ messages in thread From: Nick Hainke @ 2022-08-06 8:24 UTC (permalink / raw) To: netdev; +Cc: Nick Hainke Fixes errors in the form of: in function `ipstats_show_64': <artificial>:(.text+0x4e30): undefined reference to `MIN' Signed-off-by: Nick Hainke <vincent@systemli.org> --- ip/ipstats.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ip/ipstats.c b/ip/ipstats.c index 5cdd15ae..2f500fc8 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -6,6 +6,10 @@ #include "utils.h" #include "ip_common.h" +#ifndef MIN +#define MIN(a, b) ((a) < (b) ?
Find elsewhere
🌐
GitHub
github.com › Ebiroll › qemu_esp32 › issues › 12
build fails with `undefined reference to `major'` · Issue #12 · Ebiroll/qemu_esp32
February 24, 2019 - /home/morgan/devel/qemu-xtensa-esp32/qga/commands-posix.c: In function ‘dev_major_minor’: /home/morgan/devel/qemu-xtensa-esp32/qga/commands-posix.c:656:21: warning: implicit declaration of function ‘major’ [-Wimplicit-function-declaration] *devmajor = major(st.st_rdev); ^~~~~ /home/morgan/devel/qemu-xtensa-esp32/qga/commands-posix.c:656:21: warning: nested extern declaration of ‘major’ [-Wnested-externs] /home/morgan/devel/qemu-xtensa-esp32/qga/commands-posix.c:657:21: warning: implicit declaration of function ‘minor’; did you mean ‘mincore’? [-Wimplicit-function-declaration] *devminor = minor(st.st_rdev); ^~~~~ mincore /home/morgan/devel/qemu-xtensa-esp32/qga/commands-posix.c:657:21: warning: nested extern declaration of ‘minor’ [-Wnested-externs]
Author   morganrallen
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Error message "undefined reference" - Programming - Arduino Forum
February 19, 2023 - I've read a few posts on this topic, but I'm getting nowhere: I want to make my code more readable using object oriented structures. However, I haven't gotten far and am failing at the basics. I now have three tabs, the main program, a header tab and a CPP tab.
🌐
CodeProject
codeproject.com › Questions › 1212280 › Why-do-I-get-undefined-reference-to-errors-when-I
Why do I get "undefined reference to ..." errors ...
November 22, 2022 - Do not try and find the page. That’s impossible. Instead only try to realise the truth - For those who code; Updated: 1 Jul 2007
🌐
Google Groups
groups.google.com › g › minix3 › c › Mu_tibqqiWM
error: undefined reference to __main
There are different formats that are incompatible to different degrees. Another remarks: leading underscores in C symbols have at some point been removed and were later added again. Check in the .S files in the source trees which is the default the MINIX revision you are using.
🌐
Reddit
reddit.com › r/cpp_questions › undefined reference but it is defined
r/cpp_questions on Reddit: undefined reference but it is defined
May 30, 2023 -

i get this error:C:\Users\Owner\MadV\main.cpp|873|undefined reference to `BigNum::operator++(int)'|

when i try to use functions from my BigNum.c files, the functions have been declared in BigNum.h, these are my main.cpp includes:

include <cmath>
include <stack>
include<queue>
include <iostream>
include <ranges>
include <regex>
include <vector>
include <thread>
include <bitset>
include <ctime>
include <iterator>
include <math.h>
include <bits/stdc++.h>
include "vytecode.h"
include "debugger.h"
include "vytemachine.h"
include "BigNum.h" // never incude .c/cpp files
include <time.h>
define M_PI 3.141592653589793
include<windows.h>
include <SFML/Graphics.hpp>
include <map>
include <chrono>
include <GL/gl.h>
include <string>
define gkey GetAsyncKeyState
define rxs regex_search
define rxp regex_replace
define rxm regex_match
define icas std::regex_constants::icase
include <immintrin.h>

is there any thing causing this in the guards? in the BigNum.h file i have pragma once, so i don't think that should be causing any errors.

definition of functions in my BigNum class( in BigNum.h):

inline BigNum operator+( BigNum &other) ;

inline BigNum operator-( BigNum &other) ; // dont change to * bc its slower

inline BigNum operator*( BigNum other) ;

inline BigNum operator/( BigNum other) ;

inline void operator++(int);

inline void operator--(int);

inline bool operator>(const BigNum& other) const;

inline bool operator<(const BigNum& other) const;

inline bool operator>=(const BigNum& other) const;

inline bool operator<=(const BigNum& other) const;

inline bool operator==(const BigNum& other) const;

inline bool operator!=(const BigNum& other) const;

code that fails to compile(main.cpp):

BigNum test("1");

BigNum c ("32.5");

BigNum f("1.5");

double c2 = 5.2433423412;

int k2 = 10;

int f2;

testBool* x2;

x2 = new testBool[10000000];

auto t1 = std::chrono::high_resolution_clock::now();

for(auto i = 0; i<= 1e+7;i++)

{

c+f;

}

auto t2 = std::chrono::high_resolution_clock::now();

auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

print(c,0);

setInt(c);

print(c,0);

std::cout<<"object: "<<duration<<std::endl;

return 0;

🌐
Code::Blocks
forums.codeblocks.org › index.php
undefined reference
undefined reference · « previous next » · Send this topic · Print · Pages: [1] Go Down · Send this topic · Print · Pages: [1] Go Up · « previous next » · Code::Blocks Forums » · User forums » · Using Code::Blocks » · undefined reference · XHTML · RSS ·
🌐
Cplusplus
cplusplus.com › forum › general › 113904
[faq] undefined reference - unresolved e - C++ Forum
August 7, 2015 - Those symbols are the global variables and functions that its source defined, and also functions and variables that were referenced but that no definition was found during compilation. (you can list the symbols with the `nm' program.) The linker will later fix those calls with the information given by the the other object files. However, if it does not found what a function is supposed to do, then it would complain with the `undefined reference' error.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › fix-undefined-reference-error-in-cpp
How to Fix Undefined Reference Error in C++? - GeeksforGeeks
July 23, 2025 - In C++, the undefined reference error typically occurs during the linking phase of compilation. This error indicates that the compiler knows about a function or variable (it has been declared), but it cannot find the actual implementation (definition) during the linking process. The linker needs to resolve these references to create a complete executable.