I'm using GCC (CygWin) cross-compiling targeting an Arm7 processor. the problem is none of the standard library functions are available for my program. as I understand it, libc.a is the library i should be using. strangely, this file has been copied to the application source directory.
I would've thought if I did the following, I should be able to use these functions:
have included (enclosed in <>) string.h and stdlib.h in my LCD.c file
mention libc.a to the linker
During make, here's what it says:
$ make
.compiling
..linking
arm-elf-ld -v -Map main.map -nostartfiles -T simple.cmd -o main.out start.o ivt.
o main.o libc.a LCD.o
GNU ld version 2.14 20030612
LCD.o(.text+0x75c): In function `LCD_DispSmallDigits':
: undefined reference to `strlen'
LCD.o(.text+0x22d4): In function `LCD_DispSelMsgAt':
: undefined reference to `malloc'
LCD.o(.text+0x22e0): In function `LCD_DispSelMsgAt':
: undefined reference to `strcpy'
LCD.o(.text+0x2308): In function `LCD_DispSelMsgAt':
: undefined reference to `free'
LCD.o(.text+0x2358): In function `LCD_DispNumMsgAt':
: undefined reference to `malloc'
LCD.o(.text+0x2368): In function `LCD_DispNumMsgAt':
: undefined reference to `sprintf'
LCD.o(.text+0x2384): In function `LCD_DispNumMsgAt':
: undefined reference to `free'
the code I'm using is quite mundane:
void LCD_DispSelMsgAt(int iRow, int iCol, int bSelected, char* s)
{
int i;
char* sBuffer = (char*) malloc(100);
strcpy(sBuffer, s);
if (bSelected)
for (i=0; i<strlen(sBuffer); i++)
if ((*(sBuffer + i)>='a') && (*(sBuffer + i)<='z'))
*(sBuffer + i) = (*(sBuffer + i)) - 0x20;
LCD_DispMsgAt(iRow, iCol, sBuffer);
free(sBuffer);
}
how can I get access to those standard routines?
thank you!
PS: it seems to me I'm having quite a "general" problem so what I'm about to say is not central to this question but i'll mention it anyway...
I noticed something that specifically relates to strlen( ). the prototype for strlen( ) has the parameter as "const char* s". it seems then it works fine with:
i = strlen("abc")
but not in the code sample routine shown above. that wouldn't be a very helpful library routine that can't be used as strlen(char* s).
reply to #n.m.:
adding /gnude/arm-elf/lib/libc.a to the linker command line introduced a "thousand" errors.
$ make
..linking
arm-elf-ld -v -Map main.map -nostartfiles -T LinkerScript.cmd -L /gnude/arm-elf/
lib -o main.out start.o ivt.o main.o LCD.o /gnude/arm-elf/lib/libc.a
GNU ld version 2.14 20030612
/gnude/arm-elf/lib/libc.a(syscalls.o)(.text+0x714): In function `_sbrk':
: undefined reference to `end'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x8c0): In function `_vfprintf_r':
: undefined reference to `__eqdf2'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1054): In function `_vfprintf_r':
: undefined reference to `__nedf2'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x155c): In function `_vfprintf_r':
: undefined reference to `__umoddi3'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1578): In function `_vfprintf_r':
: undefined reference to `__udivdi3'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1834): In function `_vfprintf_r':
: undefined reference to `__ltdf2'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1d98): In function `cvt':
: undefined reference to `__eqdf2'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1e10): In function `cvt':
: undefined reference to `__nedf2'
/gnude/arm-elf/lib/libc.a(vfprintf.o)(.text+0x1e30): In function `cvt':
: undefined reference to `__negdf2'
/gnude/arm-elf/lib/libc.a(dtoa.o)(.text+0x7c): In function `_dtoa_r':
: undefined reference to `__eqdf2'
not sure what i should do next. i think i'll start by removing the explicit libc.a from the linker command line.
Related
Well, it's a very strange error I met.
When I try to compile my program with the fftw library by the command:
g++ -std=c++11 -o main main.cpp BFSCcommandlineParser.cpp BFSCframe.cpp BFSCgeometry.cpp ImageIO.cpp -lfftw3 -lm
... I get this:
/tmp/cczUuTb0.o: In function `fftw_prog::fftw_prog(char const*)':
main.cpp:(.text._ZN9fftw_progC2EPKc[_ZN9fftw_progC5EPKc]+0x5c): undefined reference to `fftwf_import_wisdom_from_file'
/tmp/cczUuTb0.o: In function `fftw_prog::~fftw_prog()':
main.cpp:(.text._ZN9fftw_progD2Ev[_ZN9fftw_progD5Ev]+0x31): undefined reference to `fftwf_export_wisdom_to_file'
/tmp/cczUuTb0.o: In function `fft<2, float, std::complex<float> >::fft(tensor<int, 2ul>, bool)':
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEEC2E6tensorIiLm2EEb[_ZN3fftILi2EfSt7complexIfEEC5E6tensorIiLm2EEb]+0xcf): undefined reference to `fftwf_plan_dft_r2c'
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEEC2E6tensorIiLm2EEb[_ZN3fftILi2EfSt7complexIfEEC5E6tensorIiLm2EEb]+0x111): undefined reference to `fftwf_plan_dft_c2r'
/tmp/cczUuTb0.o: In function `fft<2, float, std::complex<float> >::~fft()':
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEED2Ev[_ZN3fftILi2EfSt7complexIfEED5Ev]+0x25): undefined reference to `fftwf_free'
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEED2Ev[_ZN3fftILi2EfSt7complexIfEED5Ev]+0x35): undefined reference to `fftwf_destroy_plan'
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEED2Ev[_ZN3fftILi2EfSt7complexIfEED5Ev]+0x45): undefined reference to `fftwf_destroy_plan'
/tmp/cczUuTb0.o: In function `fft<2, float, std::complex<float> >::r2F()':
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEE3r2FEv[_ZN3fftILi2EfSt7complexIfEE3r2FEv]+0x25): undefined reference to `fftwf_execute'
/tmp/cczUuTb0.o: In function `fft<2, float, std::complex<float> >::F2r()':
main.cpp:(.text._ZN3fftILi2EfSt7complexIfEE3F2rEv[_ZN3fftILi2EfSt7complexIfEE3F2rEv]+0x35): undefined reference to `fftwf_execute'
collect2: error: ld returned 1 exit status
I thought it could be a problem of fftw itself, so I tested the library with a proram, and it worked. That means that it's not so.
The following code is a template from my file which is the only one in my project that uses fftw.
template <int N, typename rT, typename FT>
inline fft<N,rT,FT>::~fft() {
if (data != 0) {
if (Precision<rT>::IsFloat) {
fftwf_free((fftwf_complex *)data);
fftwf_destroy_plan((fftwf_plan_s*) r2Fplan);
fftwf_destroy_plan((fftwf_plan_s*) F2rplan);
}
else {
fftw_free((fftw_complex *)data);
fftw_destroy_plan((fftw_plan_s*) r2Fplan);
fftw_destroy_plan((fftw_plan_s*) F2rplan);
}
}
}
For single precision (float) you need to link the libfftwf library, for double precision (double) you need the libfftw library. I would guess you are just linking the latter and not the former. For gcc et al the command line needs to contain -lfftw3 -lfftw3f if you want both double and single precision support.
I'm attempting to follow the steps on http://llvm.org/docs/tutorial/LangImpl3.html to build the example.
based on
Building llvm examples
#error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
Why am I getting "undefined reference to `dladdr'" even with -ldl for this simple program?
I've ended up with the command
clang++ -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -std=c++11 -g -O3 toy.cpp `llvm-config --libs core --cppflags --ldflags` -o toy
which is giving
/usr/local/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::MutexImpl(bool)':
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:53: undefined reference to `pthread_mutexattr_init'
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:59: undefined reference to `pthread_mutexattr_settype'
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:67: undefined reference to `pthread_mutexattr_destroy'
/usr/local/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::tryacquire()':
/home/abdev/llvmHome/llvm/lib/Support/Mutex.cpp:109: undefined reference to `pthread_mutex_trylock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::RWMutexImpl()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:59: undefined reference to `pthread_rwlock_init'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::~RWMutexImpl()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:72: undefined reference to `pthread_rwlock_destroy'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::reader_acquire()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:82: undefined reference to `pthread_rwlock_rdlock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::reader_release()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:92: undefined reference to `pthread_rwlock_unlock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::writer_acquire()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:102: undefined reference to `pthread_rwlock_wrlock'
/usr/local/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::writer_release()':
/home/abdev/llvmHome/llvm/lib/Support/RWMutex.cpp:112: undefined reference to `pthread_rwlock_unlock'
/usr/local/lib/libLLVMSupport.a(Signals.o): In function `llvm::sys::PrintStackTrace(_IO_FILE*)':
/home/abdev/llvmHome/llvm/lib/Support/Unix/Signals.inc:278: undefined reference to `dladdr'
/home/abdev/llvmHome/llvm/lib/Support/Unix/Signals.inc:290: undefined reference to `dladdr'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::ThreadLocalImpl()':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:56: undefined reference to `pthread_key_create'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::~ThreadLocalImpl()':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:63: undefined reference to `pthread_key_delete'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::setInstance(void const*)':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:70: undefined reference to `pthread_setspecific'
/usr/local/lib/libLLVMSupport.a(ThreadLocal.o): In function `llvm::sys::ThreadLocalImpl::getInstance()':
/home/abdev/llvmHome/llvm/lib/Support/ThreadLocal.cpp:77: undefined reference to `pthread_getspecific'
/usr/local/lib/libLLVMSupport.a(Threading.o): In function `llvm::llvm_execute_on_thread(void (*)(void*), void*, unsigned int)':
/home/abdev/llvmHome/llvm/lib/Support/Threading.cpp:91: undefined reference to `pthread_attr_setstacksize'
/home/abdev/llvmHome/llvm/lib/Support/Threading.cpp:96: undefined reference to `pthread_create'
/home/abdev/llvmHome/llvm/lib/Support/Threading.cpp:100: undefined reference to `pthread_join'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Am I missing a library, or is some of the order incorrect?
I believe you need to link with -lpthread or just -pthread
I'm trying to develop a packet analyzer with CUDA support for pattern matching. I'm using GTK+ for GUI creation but I am not able to compile the GUI file together with the cuda files. How to write makefile for this case?
The project is having two parts: 1. Analyzer 2. GUI
Analyzer consists of many .c,.h files and one .cu file.
GUI part has only one file gui.c
I have included packet_analyzer.h in gui.c.
I tried the following makefile
all: guitest
guitest: gui.o list.o queue.o Word.o dictionary.o packet_capturer.o rule.o aho-corasick.o aho-corasick_cuda.o packet_analyzer.o
gcc -lpcap -lpthread `pkg-config --cflags --libs gtk+-2.0` gui.o list.o queue.o Word.o dictionary.o packet_capturer.o rule.o aho-corasick.o aho-corasick_cuda.o packet_analyzer.o
gui.o: gui.c
gcc -lpcap -lpthread -c `pkg-config --cflags --libs gtk+-2.0` gui.c
list.o : list.c
gcc -c list.c
queue.o : queue.c
gcc -c queue.c
Word.o : Word.c Word.h
gcc -c Word.c
dictionary.o : dictionary.c
gcc -c dictionary.c
rule.o : rule.c rule.h
gcc -c rule.c rule.h
packet_capturer.o : packet_capturer.c
gcc -lpcap -lpthread -c packet_capturer.c
aho-corasick.o : aho-corasick.c
gcc -lpcap -lpthread -c aho-corasick.c
aho-corasick_cuda.o : aho-corasick_cuda.cu
nvcc -lpcap -lpthread -c aho-corasick_cuda.cu
packet_analyzer.o : packet_analyzer.c
gcc -lpcap -lpthread -c packet_analyzer.c
clean:
rm -rf *o guitest
i end up with the following errors:
aho-corasick_cuda.o: In function `transfer_tries_from_hosttodevice(int, int, int)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x37): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x5d): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x86): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xac): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xd5): undefined reference to `cudaMalloc'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xfb): more undefined references to `cudaMalloc' follow
aho-corasick_cuda.o: In function `transfer_tries_from_hosttodevice(int, int, int)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x132): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x166): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x19d): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x1d1): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x208): undefined reference to `cudaMemcpy'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x23c): more undefined references to `cudaMemcpy' follow
aho-corasick_cuda.o: In function `transfer_packets_from_hosttodevice(void*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x3b1): undefined reference to `Queue_dequeue(Queue*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x519): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x52b): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x53d): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x56b): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x58b): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x5ab): undefined reference to `cudaMemcpy'
aho-corasick_cuda.o: In function `analyze_packets(void*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x663): undefined reference to `cudaMalloc'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x683): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x6dd): undefined reference to `cudaConfigureCall'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x777): undefined reference to `cudaMemcpy'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x78a): undefined reference to `Queue_dequeue(Queue*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x7d5): undefined reference to `Queue_enqueue(Queue*, void*)'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x7f3): undefined reference to `cudaFree'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x802): undefined reference to `cudaFree'
aho-corasick_cuda.o: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x824): undefined reference to `__cudaUnregisterFatBinary'
aho-corasick_cuda.o: In function `__device_stub__Z14AC_search_CudaPiS_S_S_S_S_S_S_PhiS_(int*, int*, int*, int*, int*, int*, int*, int*, unsigned char*, int, int*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x85c): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x87f): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8a2): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8c5): undefined reference to `cudaSetupArgument'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8e8): undefined reference to `cudaSetupArgument'
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x90b): more undefined references to `cudaSetupArgument' follow
aho-corasick_cuda.o: In function `__sti____cudaRegisterAll_52_tmpxft_00001608_00000000_4_aho_corasick_cuda_cpp1_ii_9958a654()':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xa82): undefined reference to `__cudaRegisterFatBinary'
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xae3): undefined reference to `__cudaRegisterFunction'
aho-corasick_cuda.o: In function `cudaError cudaLaunch<char>(char*)':
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text._Z10cudaLaunchIcE9cudaErrorPT_[cudaError cudaLaunch<char>(char*)]+0x14): undefined reference to `cudaLaunch'
aho-corasick_cuda.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [guitest] Error 1
You need to link with the CUDA runtime library. Add -lcudart to your link command (and CUDA lib path if necessary).
It's the nvcc -lpcap -lpthread $(ANALYZER) -o packet_analyzer.o line that's failing, right? With the -o option, you're telling it to build a complete executable, not just the object files. It needs a main function to do that, which I presume you don't have in any of the $(ANALYZER) files. Instead, try compiling all the sources with the -c flag (like you've done with gcc for gui.c), and then wrap it all together and link it with the other gcc command.
Once I installed Ubuntu 11.10, strange error appears. I want to use GD with my C program, so I installed package "libgd2-xpm-dev". Everything was installed - files gd.h and libgd.a are in "/usr/include" and in "/usr/lib". So, I've tried to compile simple program with GD.
#include <stdio.h>
#include <gd.h>
int main()
{
gdImagePtr im, im_clear;
int black, white;
FILE *out1;
im = gdImageCreate(100, 100);
im_clear = gdImageCreate(100, 100);
white = gdImageColorAllocate(im, 255, 255, 255);
black = gdImageColorAllocate(im, 0, 0, 0);
return 0;
}
$ gcc -lgd gd.c
/tmp/cc6LReuX.o: In function `main':
gd2.c:(.text+0x19): undefined reference to `gdImageCreate'
gd2.c:(.text+0x31): undefined reference to `gdImageCreate'
gd2.c:(.text+0x59): undefined reference to `gdImageColorAllocate'
gd2.c:(.text+0x81): undefined reference to `gdImageColorAllocate'
Wait, what? Okay, let's check something.
# Let's sure the lib was found.
$ gcc -lgd_something gd.c
/usr/bin/ld: cannot find -lgd_something
# Lets sure we made no mistake with the symbol's name
$ nm /usr/lib/libgd.a
...
00000dc0 T gdImageColorAllocate
...
000003b0 T gdImageCreate
# So, everything should be ok
$ gcc -lgd gd.c
/tmp/cc6LReuX.o: In function `main':
gd2.c:(.text+0x19): undefined reference to `gdImageCreate'
gd2.c:(.text+0x31): undefined reference to `gdImageCreate'
gd2.c:(.text+0x59): undefined reference to `gdImageColorAllocate'
gd2.c:(.text+0x81): undefined reference to `gdImageColorAllocate'
$ echo $LD_LIBRARY_PATH
# Nothing
And I don't know what shall I do. Is it an error in gcc or I do something wrong. On my previous os (Ubuntu 10.04) everything works well.
Which file should I show for you?
Change:
$ gcc -lgd gd.c
to:
$ gcc gd.c -lgd
(Reason: link order matters !)
Oh, and add -Wall while you're at it - it pains me greatly every time I see people compiling with warnings disabled.
$ gcc -Wall gd.c -lgd
it seems I can no longer compile my code in GCC post Ubuntu 11.10 update, despite linking in the libraries with -l. Compiling with:
gcc -lm -lGL -lGLU -lglut T1.c
(The two libraries i'm trying to link and have as includes are glut and math)
All the libraries and header files are where they're supposed to be (they haven't gone anywhere since the update) and i've checked all my relevant package installations. In addition here are my environment variables and they seem to be in order:
PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
C_INCLUDE_PATH=/usr/include
I don't think it's a problem with the code as i'm unable to compile files I successfully compiled yesterday. But i'll link it anyway just in case:
#include <math.h>
#include <GL/glut.h>
const int WIDTH=640;
const int HEIGHT=480;
const float NEAR_CLIP=0.1f;
const float FAR_CLIP=100.0f;
const double INC_ROTATE=5;
double rotate=0;
void rotateObject() {
rotate+=INC_ROTATE;
}
void update() {
//rotateObject();
}
void drawAxes() {
double x = 1.5, y = 1.5, z = 1.5;
glLineWidth(4);
glBegin(GL_LINES);
glColor3d(1,0,0);
glVertex3d(0,0,0);
glVertex3d(x,0,0);
glColor3d(0,1,0);
glVertex3d(0,0,0);
glVertex3d(0,y,0);
glColor3d(0,0,1);
glVertex3d(0,0,0);
glVertex3d(0,0,z);
glEnd();
glLineWidth(1);
}
void render() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(1.2,1.0,2.5,0.0,0.0,0.0,0.0,1.0,0.0);
drawAxes();
glColor3d(1,1,1);
glRotated(rotate,0,0,1);
glutWireCube(1);
}
void display() {
update();
render();
}
void reshape(int width, int height) {
float fAspect=0;
float fovy=(M_PI/3);
float top=tan(fovy*0.5)*NEAR_CLIP;
float bottom=top;
float left=fAspect*bottom;
float right=fAspect*top;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left,right,bottom,top,NEAR_CLIP, FAR_CLIP);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char **argv) {
glClearColor(0,0,0,1);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("T1");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(display);
glutMainLoop();
return 1;
}
Error messages:
T1.c:(.text+0x63): undefined reference to `glLineWidth'
T1.c:(.text+0x6d): undefined reference to `glBegin'
T1.c:(.text+0x82): undefined reference to `glColor3d'
T1.c:(.text+0x93): undefined reference to `glVertex3d'
T1.c:(.text+0xa5): undefined reference to `glVertex3d'
T1.c:(.text+0xba): undefined reference to `glColor3d'
T1.c:(.text+0xcb): undefined reference to `glVertex3d'
T1.c:(.text+0xe1): undefined reference to `glVertex3d'
T1.c:(.text+0xf6): undefined reference to `glColor3d'
T1.c:(.text+0x107): undefined reference to `glVertex3d'
T1.c:(.text+0x11d): undefined reference to `glVertex3d'
T1.c:(.text+0x122): undefined reference to `glEnd'
T1.c:(.text+0x12f): undefined reference to `glLineWidth'
/tmp/cc4VqRwQ.o: In function `render':
T1.c:(.text+0x143): undefined reference to `glClear'
T1.c:(.text+0x148): undefined reference to `glLoadIdentity'
T1.c:(.text+0x18a): undefined reference to `gluLookAt'
T1.c:(.text+0x1b1): undefined reference to `glColor3d'
T1.c:(.text+0x1ce): undefined reference to `glRotated'
T1.c:(.text+0x1db): undefined reference to `glutWireCube'
/tmp/cc4VqRwQ.o: In function `reshape':
T1.c:(.text+0x22e): undefined reference to `tan'
T1.c:(.text+0x28a): undefined reference to `glViewport'
T1.c:(.text+0x294): undefined reference to `glMatrixMode'
T1.c:(.text+0x299): undefined reference to `glLoadIdentity'
T1.c:(.text+0x2da): undefined reference to `glFrustum'
T1.c:(.text+0x2e4): undefined reference to `glMatrixMode'
/tmp/cc4VqRwQ.o: In function `main':
T1.c:(.text+0x30b): undefined reference to `glClearColor'
T1.c:(.text+0x31e): undefined reference to `glutInit'
T1.c:(.text+0x328): undefined reference to `glutInitDisplayMode'
T1.c:(.text+0x337): undefined reference to `glutInitWindowPosition'
T1.c:(.text+0x346): undefined reference to `glutInitWindowSize'
T1.c:(.text+0x350): undefined reference to `glutCreateWindow'
T1.c:(.text+0x35d): undefined reference to `glutDisplayFunc'
T1.c:(.text+0x367): undefined reference to `glutReshapeFunc'
T1.c:(.text+0x374): undefined reference to `glutIdleFunc'
T1.c:(.text+0x379): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
I honestly have no clue why gcc can't find the required source files. Any help you could supply would be greatly appreciated, thanks in advance.
EDIT:
I'm using freeglut
Added error messages
I'm guessing ld (the linker) has been changed to work a bit differently.
Put your libraries after the source file
gcc T1.c -lm -lGL -lGLU -lglut
Or apt-get install binutils-gold , apparently the new gold linker will still process dependent shared libraries even if they appear first on the command line.