If you compile using gcc, you might need to add -lm option to link to the math library (libm) like
gcc test.c -lm
Answer from Andrei B on Stack OverflowGitHub
github.com › eviltrout › tis-100 › issues › 1
undefined reference to `trunc' · Issue #1 · eviltrout/tis-100
May 29, 2015 - Building locally results in a linker error referencing trunc. $ make build/output.o: In function `output_program': output.c:(.text+0x461): undefined reference to `trunc' collect2: error: ld returned 1 exit status trunc is located in libm...
Author gim
Ask Ubuntu
askubuntu.com › questions › 939888 › error-compilling-program-with-makefile-undefined-reference-to-symbol-truncg
compiling - Error compilling program with makefile : undefined reference to symbol 'trunc@@GLIBC_2.2.5' - Ask Ubuntu
Most likely the issue is that your link rules $(CC) $(LFLAGS) $(SNAPMERGE_OBJ) -o ../bin/snapmerge and so on place the libraries ahead of the object files: see for example Why does the order of '-l' option in gcc matter?
The Coding Forums
thecodingforums.com › archive › archive › c programming
undefined reference to `trunc' | C Programming | Coding Forums
October 23, 2004 - I can't understand where is the problem: this is the file I would like to compile ------------------------ #include <math.h> #include <stdlib.h> int main (){ int c = trunc(17.5); return c; } Click to expand... Try gcc -o prova prova.c -lm where m is for the math library and the l is the letter ell. HTH Bjørn · K · Nov 24, 2004 · #4 · Giulio said: ----------------------------- /tmp/cc0ZzTZJ.o: In function `main': /tmp/cc0ZzTZJ.o(.text+0x32): undefined reference to `trunc' collect2: ld returned 1 exit status ------------------------------------------------ Click to expand...
Bytes
bytes.com › home › forum › topic
undefined reference to `trunc' - Post.Byes
Re: undefined reference to `trunc' Giulio wrote: [color=blue] > I can't understand where is the problem: > this is the file I would like to compile > ------------------------ > #include <math.h> > #include <stdlib.h> > > int main (){ > int c = trunc(17.5); > return c; > } > -------------------------- > > with this command: > -------------------- > gcc -o prova prova.c[/color] Try gcc -o prova prova.c -lm where m is for the math library and the l is the letter ell.
Top answer 1 of 2
5
If you compile using gcc, you might need to add -lm option to link to the math library (libm) like
gcc test.c -lm
2 of 2
1
It seems that you will need the info about how C source code are compiled and linked together. The link contains some basic info: Compile & Link
You use -I option of gcc to specify where to find headers, and -l option to link standard libraries
Texas Instruments E2E
e2e.ti.com › support › processors-group › processors › f › processors-forum › 993066 › c6000-cgt-compile-issue-caused-by-define-trunc-in-math-h
C6000-CGT: Compile issue caused by '#define trunc' in math.h - Processors forum - Processors - TI E2E support forums
Part Number: C6000-CGT It seems that the standard include file math.h has a define for trunc, this gives issues with std::ios::trunc symbol (defined in e.g. ios
Stack Overflow
stackoverflow.com › questions › 45321074 › error-compiling-program-with-makefile-on-linux-with-openmpi-undefined-reference
c - Error compiling program with makefile on Linux with openmpi: undefined reference to symbol 'trunc@@GLIBC_2.2.5' - Stack Overflow
I am trying to compile a program on Linux+openmpi using a makefile but got this error: I have looked at answers to similar issues but can still fix it. mpicc -lmpi -lm -ldl hh_visco.o hh_elastic.o
Arch Linux Forums
bbs.archlinux.org › viewtopic.php
[solved]Problem installing cinnamon / Newbie Corner / Arch Linux Forums
make all-recursive make[1]: Entering ... `floorf@GLIBC_2.2.5' /usr/lib/libgtk-3.so: undefined reference to `round@GLIBC_2.2.5' /usr/lib/libpng15.so.15: undefined reference to `trunc@GLIBC_2.2.5' /usr/lib/libgtk-3.so: undefined reference to `nearbyint@GLIBC_2.2.5' /usr/lib/libgtk-3.so: undefined ...
GitHub
github.com › lingnand › RPD › issues › 1
编译过程遇到链接问题 · Issue #1 · lingnand/RPD
April 9, 2013 - 5.100 libavfilter 3. 90.100 / 3. 90.100 libswscale 2. 5.101 / 2. 5.101 libswresample 0. 17.104 / 0. 17.104 Hyper fast Audio and Video encoder usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}... ... pi@raspberrypi ~/fmd $ make gcc -Wall -o fmd app.o config.o downloader.o player.o playlist.o server.o util.o validator.o -lcurl -ljson-c -lao -lpthread -lavcodec -lavutil -lavformat -lswresample -lcrypto /usr/local/lib/libavcodec.a(amrnbdec.o): In function `amrnb_decode_frame': /home/pi/ffmpeg-2.1.1/libavcodec/amrnbdec.c:1035: undefined reference to `truncf' /usr/l
Author lapsule
Intel Community
community.intel.com › t5 › Intel-oneAPI-DPC-C-Compiler › Undefined-reference-to-truncdfhf2 › td-p › 1675111
Undefined reference to `__truncdfhf2' - Intel Community
March 14, 2025 - However, when I attempt to compile it using the icx command "icx -march=znver2 -ffp-eval-method=source -fno-fast-math test.c -O0" I get an error about missing __truncdfhf2: /tmp/icx-5661a33e8a/test-cacdee.o: In function `main': test.c:(.text+0x16): undefined reference to `__truncdfhf2' icx: error: linker command failed with exit code 1 (use -v to see invocation) It seems this instruction is contained in compiler-rt, but when I add "-rtlib=compiler-rt" I get the errors: /usr/bin/ld: cannot find /opt/intel/oneapi/compiler/2024.1/lib/clang/18/lib/linux/libclang_rt.builtins-x86_64.a: No such file or directory /usr/bin/ld: cannot find /opt/intel/oneapi/compiler/2024.1/lib/clang/18/lib/linux/libclang_rt.builtins-x86_64.a: No such file or directory ·
GitHub
github.com › bytecodealliance › wasmtime › issues › 8898
Unable to link a binary with wasmtime and musl · Issue #8898 · bytecodealliance/wasmtime
July 3, 2024 - = note: /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libm-2.35.a(e_pow.o): warning: relocation against `_dl_x86_cpu_features' in read-only section `.text' /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libm-2.35.a(s_ceil.o): in function `__ceil_ifunc': (.text+0x6): undefined reference to `_dl_x86_cpu_features' /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libm-2.35.a(s_trunc.o): in function `__trunc_ifunc': (.text+0x6): undefined reference to `_dl_x86_cpu_features' /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libm-2.35.a(s_fma.o): in function `__fma_ifunc': (.text+0xafd): undefined reference to `_dl_x86_cpu_features' /u
Author pimeys
GitHub
github.com › protocolbuffers › protobuf › issues › 10805
undefined reference to google::protobuf::internal::ArenaStringPtr::Destroy() · Issue #10805 · protocolbuffers/protobuf
September 12, 2022 - PromptForAddress(address_book.add_people()); { // Write the new address book back to disk. fstream output(argv[1], ios::out | ios::trunc | ios::binary); if (!address_book.SerializeToOstream(&output)) { cerr << "Failed to write address book." << endl; return -1; } } // Optional: Delete all global objects allocated by libprotobuf. google::protobuf::ShutdownProtobufLibrary(); return 0; } ... /usr/bin/ld: CMakeFiles/protoc_example.dir/main.cpp.o: in function `PromptForAddress(tutorial::Person*)': main.cpp:(.text+0x165): undefined reference to `google::protobuf::internal::ArenaStringPtr::Set(std::_
Author BinBrian
Stack Overflow
stackoverflow.com › questions › 72226490 › undefined-reference-error-when-trying-to-compile-a-fortran-program-with-extern
compilation - "undefined reference" error when trying to compile a fortran program with external dependencies using ifort - Stack Overflow
ld: /path_to_my_file/my_file.o: ...0:(.text+0xcc0a): undefined reference to `h5p_mp_h5pcreate_f_' ld: my_file.f90:(.text+0xcc2a): undefined reference to `h5global_mp_h5f_acc_trunc_f_' ld: my_file.f90:(.text+0xcc45): undefined reference to `h5f_mp_h5fcreate_f_' ld: ...
Intel Community
community.intel.com › t5 › Intel-oneAPI-DPC-C-Compiler › Undefined-reference-to-truncdfhf2 › m-p › 1675942
Re: Undefined reference to `__truncdfhf2' - Intel Community
March 18, 2025 - $ icx -march=znver2 -ffp-eval-method=source -fno-fast-math t5.c -Wno-implicit-function-declaration -O0 /usr/bin/ld: /tmp/icx-d4bfb2a574/t5-9cbced.o: in function `main': t5.c:(.text+0x16): undefined reference to `__truncdfhf2' icx: error: linker command failed with exit code 1 (use -v to see ...
Cppreference
en.cppreference.com › w › c › numeric › math › trunc
trunc, truncf, truncl - cppreference.com
4) Type-generic macro: If arg has type long double, truncl is called. Otherwise, if arg has integer type or the type double, trunc is called. Otherwise, truncf is called. If no errors occur, the nearest integer value not greater in magnitude than arg (in other words, arg rounded towards zero), is returned.