I have a sample code temp.c:
#include "win.h"
win.h is in /home/me/Documents/Code/libs/TUI/win.h and has all the declared functions
which functions are defined in some files in /home/me/Documents/Code/libs/TUI/win/[lots of files].c which every file starts with
#include "../win.h"
//functions
So while using gcc -I /home/me/Documents/Code/libs/TUI /home/me/Documents/Code/temp.c -o /home/me/Documents/Code/temp, gcc returns every function used in temp.c declared in win.h as undefined
Exact output:
gcc -g -I/home/me/Documents/Code/libs/TUI /home/me/Documents/Code/temp.c -o /home/pk/Documents/Code/temp
/usr/bin/ld: /tmp/cc4berEn.o: in function `main':
/home/me/Documents/Code/temp.c:8: undefined reference to `innit'
/usr/bin/ld: /home/me/Documents/Code/temp.c:11: undefined reference to `newTable'
/usr/bin/ld: /home/me/Documents/Code/temp.c:13: undefined reference to `tableSetHeaders'
/usr/bin/ld: /home/me/Documents/Code/temp.c:35: undefined reference to `tableAppendRow'
/usr/bin/ld: /home/me/Documents/Code/temp.c:45: undefined reference to `printTable'
collect2: error: ld returned 1 exit status
notes
Using -I /home/me/Documents/Code/libs/TUI/win.h returns fatal error: win.h: No such file or directory 3 | #include "win.h"
/home/me/Documents/Code/libs/TUI is a folder
Writing every source file's name is not an option
Already tried this
-g for debug
Related
I am new to Opencl Programming. I have written a matrix multiplication program while compiling it is giving me error
My include files are:
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.h>
#include <stdbool.h>
But I got an error as:
/usr/bin/ld: /tmp/ccxNPkyU.o: in function `main':
gmm.c:(.text+0x2d3): undefined reference to `clGetPlatformIDs'
/usr/bin/ld: gmm.c:(.text+0x2ef): undefined reference to `clGetPlatformIDs'
/usr/bin/ld: gmm.c:(.text+0x322): undefined reference to `clGetDeviceIDs'
/usr/bin/ld: gmm.c:(.text+0x376): undefined reference to `clCreateContext'
/usr/bin/ld: gmm.c:(.text+0x527): undefined reference to `clCreateCommandQueue'
/usr/bin/ld: gmm.c:(.text+0x5ab): undefined reference to `clCreateProgramWithSource'
/usr/bin/ld: gmm.c:(.text+0x5fc): undefined reference to `clBuildProgram'
/usr/bin/ld: gmm.c:(.text+0x64c): undefined reference to `clGetProgramBuildInfo'
/usr/bin/ld: gmm.c:(.text+0x682): undefined reference to `clCreateKernel'
/usr/bin/ld: gmm.c:(.text+0x6dc): undefined reference to `clCreateBuffer'
/usr/bin/ld: gmm.c:(.text+0x70c): undefined reference to `clCreateBuffer'
/usr/bin/ld: gmm.c:(.text+0x73c): undefined reference to `clCreateBuffer'
/usr/bin/ld: gmm.c:(.text+0x76e): undefined reference to `clCreateBuffer'
/usr/bin/ld: gmm.c:(.text+0x7a0): undefined reference to `clCreateBuffer'
/usr/bin/ld: /tmp/ccxNPkyU.o:gmm.c:(.text+0x7d2): more undefined references to `clCreateBuffer' follow
/usr/bin/ld: /tmp/ccxNPkyU.o: in function `main':
gmm.c:(.text+0x84c): undefined reference to `clSetKernelArg'
/usr/bin/ld: gmm.c:(.text+0x875): undefined reference to `clSetKernelArg'
/usr/bin/ld: gmm.c:(.text+0x89e): undefined reference to `clSetKernelArg'
/usr/bin/ld: gmm.c:(.text+0x8c7): undefined reference to `clSetKernelArg'
/usr/bin/ld: gmm.c:(.text+0x8f8): undefined reference to `clSetKernelArg'
/usr/bin/ld: /tmp/ccxNPkyU.o:gmm.c:(.text+0x929): more undefined references to `clSetKernelArg' follow
/usr/bin/ld: /tmp/ccxNPkyU.o: in function `main':
gmm.c:(.text+0xa58): undefined reference to `clEnqueueReadBuffer'
/usr/bin/ld: gmm.c:(.text+0xa9f): undefined reference to `clEnqueueReadBuffer'
/usr/bin/ld: gmm.c:(.text+0xae6): undefined reference to `clEnqueueReadBuffer'
/usr/bin/ld: gmm.c:(.text+0xb04): undefined reference to `clWaitForEvents'
/usr/bin/ld: gmm.c:(.text+0xb13): undefined reference to `clFinish'
/usr/bin/ld: gmm.c:(.text+0xb3c): undefined reference to `clGetEventProfilingInfo'
/usr/bin/ld: gmm.c:(.text+0xb65): undefined reference to `clGetEventProfilingInfo'
/usr/bin/ld: gmm.c:(.text+0xc9f): undefined reference to `clReleaseMemObject'
/usr/bin/ld: gmm.c:(.text+0xcae): undefined reference to `clReleaseMemObject'
/usr/bin/ld: gmm.c:(.text+0xcbd): undefined reference to `clReleaseMemObject'
/usr/bin/ld: gmm.c:(.text+0xccc): undefined reference to `clReleaseMemObject'
/usr/bin/ld: gmm.c:(.text+0xcdb): undefined reference to `clReleaseMemObject'
/usr/bin/ld: /tmp/ccxNPkyU.o:gmm.c:(.text+0xcea): more undefined references to `clReleaseMemObject' follow
collect2: error: ld returned 1 exit status
I am compiling program by this statement:gcc -o gmmc gmm.c. Can anyone help me
Link your program with the OpenCL library:
gcc -O2 -Wall -o gmmc gmmc.c -lOpenCL
If this doesn't find the library, you need to pass the path to it:
gcc -O2 -Wall -o gmmc gmmc.c -L/insert/path/here -lOpenCL
where /insert/path/here is the directory that contains libOpenCL.so. You can search a directory for it, e.g.
find /usr/lib -name libOpenCL.so
When I compile my makefile, I encounter this problem:
gcc parser.tab.o -o parser.tab
/usr/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
parser.tab.o: In function `yyparse':
parser.tab.c:(.text+0x2c3): undefined reference to `yylex'
parser.tab.c:(.text+0x3f5): undefined reference to `execute'
parser.tab.c:(.text+0x82b): undefined reference to `yyerror'
parser.tab.c:(.text+0x947): undefined reference to `yyerror'
collect2: ld returned 1 exit status
make: *** [parser.tab] Error 1
Here is my make file:
CC = gcc
CFLAGS = -lreadline
PROGS = d8sh parser.tab executor lexer
all: $(PROGS)
clean:
rm -f *.o $(PROGS) *.tmp
d8sh: d8sh.o
d8sh.o: executor.h lexer.h
executor.o: command.h
lexer.o: parser.tab.h
parser.tab.o: command.h
Only d8sh.c has a main function. Can anyone figure out what the problem is?
Already fixed it thx
I got 5 files:
cdouble.c cdouble.h cmatrix.c cmatrix.h and main.c
in my cdouble.c I have:
#include "cdouble.h"
in my cmatrix.c I have:
#include "cmatrix.h"
(in my cmatrix.h file i got: #include "cdouble.h"
And in my main file I have:
#include "cmatrix.h"
I need to compile it on my university's unix(?) server.
I tried:
gcc -c cmatrix.c
gcc cmatrix.o main.c
but I got many "undefined reference errors"
$ gcc -c cmatrix.c
gcc cmatrix.o main.c:
/tmp/ccZD6esL.o: In function ishermitian:
main.c:(.text+0x7b): undefined reference to cConj
main.c:(.text+0x8b): undefined reference to getCDoubleImag
main.c:(.text+0xa0): undefined reference to getCDoubleReal
main.c:(.text+0xde): undefined reference to getCDoubleImag
main.c:(.text+0xef): undefined reference to getCDoubleImag
main.c:(.text+0x111): undefined reference to getCDoubleReal
main.c:(.text+0x122): undefined reference to getCDoubleReal
/tmp/ccZD6esL.o: In function scancdouble:
main.c:(.text+0x203): undefined reference to newCDouble
/tmp/ccZD6esL.o: In function main:
main.c:(.text+0x2d8): undefined reference to getCDoubleImag
main.c:(.text+0x2fc): undefined reference to getCDoubleReal
collect2: error: ld returned 1 exit status
You need to compile cdouble.c and link its .o file as well. E.g:
gcc -c cmatrix.c
gcc -c cdouble.c
gcc main.c cmatrix.o cdouble.o
or, more simply:
gcc main.c cmatrix.c cdouble.c
I am trying to use a 3rd party library (.so) file in my project. A very simple program to do that:
#include "LibGent.h"
#include "genttypes.h"
int main() {
GT_LIB* gtLib = LibGentGet();
return 0;
}
I compile/link the program above against libgent.so:
gcc testing.c -L/home/username/proj -lgent
I get the following error:
/tmp/ccALOJwU.o: In function `main': testing.c:(.text+0x11): undefined reference to `LibGentGet'
collect2: error: ld returned 1 exit status
However, I can see that the function LibGentGet is defined in the .so file:
readelf -Ws libgent.so | grep "LibGentGet"
301: 0000000000044820 8 FUNC LOCAL DEFAULT 8 LibGentGet
What am I doing wrong?
I am using Cygwin environment with Lua Interpreter package included while cygwin installation.
So I am able to compile and run sample lua progs.
But when i try to execute a sample c file which has lua calls , i am always getting this following error.
$ cc -o ../samples/ctest -Wall ../samples/ctest.c
/tmp/ccOYgLj4.o:ctest.c:(.text+0x2b): undefined reference to `_luaL_newstate'
/tmp/ccOYgLj4.o:ctest.c:(.text+0x3d): undefined reference to `_luaL_openlibs'
/tmp/ccOYgLj4.o:ctest.c:(.text+0x59): undefined reference to `_luaL_loadfile'
/tmp/ccOYgLj4.o:ctest.c:(.text+0x82): undefined reference to `_lua_pcall'
/tmp/ccOYgLj4.o:ctest.c:(.text+0xb8): undefined reference to `_lua_getfield'
/tmp/ccOYgLj4.o:ctest.c:(.text+0xd5): undefined reference to `_lua_call'
/tmp/ccOYgLj4.o:ctest.c:(.text+0xf0): undefined reference to `_lua_close'
collect2: ld returned 1 exit status
My sample ctest.c file contents:
#include <stdio.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
/* lua interpreter */
lua_State* l;
int main () {
int dofile;
/* initialize lua */
l = lua_open();
/* load lua libraries */
luaL_openlibs(l);
/* run the hello.lua script */
dofile = luaL_dofile(l, "hello.lua");
if (dofile == 0) {
/* call foo */
lua_getglobal(l,"foo");
lua_call(l,0,0);
}
else {
printf("Error, unable to run hello.lua\n");
}
/* cleanup Lua */
lua_close(l);
return 0;
}
hello.lua file contents:
print("from c hurray")
on searching the net everywhere they say some linker error and have to include -llua51. So i tried the following .
$ cc -o ../samples/ctest -Wall -llua5.1 ../samples/ctest.c
/tmp/cc3v5Nim.o:ctest.c:(.text+0x2b): undefined reference to `_luaL_newstate'
/tmp/cc3v5Nim.o:ctest.c:(.text+0x3d): undefined reference to `_luaL_openlibs'
/tmp/cc3v5Nim.o:ctest.c:(.text+0x59): undefined reference to `_luaL_loadfile'
/tmp/cc3v5Nim.o:ctest.c:(.text+0x82): undefined reference to `_lua_pcall'
/tmp/cc3v5Nim.o:ctest.c:(.text+0xb8): undefined reference to `_lua_getfield'
/tmp/cc3v5Nim.o:ctest.c:(.text+0xd5): undefined reference to `_lua_call'
/tmp/cc3v5Nim.o:ctest.c:(.text+0xf0): undefined reference to `_lua_close'
collect2: ld returned 1 exit status
Vedhashree#Vedhashree-PC /cygdrive/c/cygwin/bin
$ ls /usr/lib/liblua*.a
/usr/lib/liblua.a /usr/lib/liblua5.1.a
/usr/lib/liblua.dll.a /usr/lib/liblua5.1.dll.a
Can you help me fix this issue and make my first embedded lua c program work?
Update:
$ cc -o ctesing -Wall ctesting.c -llua5.1
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find
-llua5.1
collect2: ld returned 1 exit status
-----------------------------------------------------------------
cc -o ../samples/ctest -Wall ../samples/ctest.c -llua
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find
-llua51
collect2: ld returned 1 exit status
-----------------------------------------------------------------
cc -o ../samples/ctest -Wall ../samples/ctest.c -llua51
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find
-llua
collect2: ld returned 1 exit status
-----------------------------------------------------------------
Still I get only these errors :(
Place -llua5.1 after ../samples/ctest.c. Objects should be linked in reverse order of dependency.
cc -o ../samples/ctest -Wall ../samples/ctest.c -llua5.1
UPDATE: Your update describes a different problem. In this case the linker cannot find a liblua5.1.a file in its search path. Make sure that you have such a library on your system and try adding its path using the -L option.