i'm trying to include all SDL libraries that i have already installed and exist in '/usr/include/SDL' this directory contains all .h files
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
int main ()
{
SDL_Surface *screen=NULL ;
SDL_Init (SDL_INIT_VIDEO);
if (SDL_Init(SDL_INIT_VIDEO !=0))
{
printf("erreur");
return 1 ;
}
screen=SDL_SetVideoMode (400,400,32,SDL_HWSURFACE | SDL_DOUBLEBUF);
if (screen== NULL)
{
printf("Unable to set video mode : %s \n",SDL_GetError() );
return 1;
}
SDL_Flip (screen);
SDL_Quit ();
return 0;
}
when i compile code above that exists in main.c in terminal using this command:
gcc main.c -o program -LSDL
i get this :
axemaster#ubuntu:~/Desktop/stackoverflow$ gcc main.c -o program -LSDL
/tmp/ccMx1per.o: In function `main':
main.c:(.text+0x16): undefined reference to `SDL_Init'
main.c:(.text+0x20): undefined reference to `SDL_Init'
main.c:(.text+0x53): undefined reference to `SDL_SetVideoMode'
main.c:(.text+0x63): undefined reference to `SDL_GetError'
main.c:(.text+0x88): undefined reference to `SDL_Flip'
main.c:(.text+0x8d): undefined reference to `SDL_Quit'
collect2: error: ld returned 1 exit status
How can i solve this ?
Related
So I am trying to make game in C using SDL2 (both i686-w64... and x86...)
This is code I have:
#include "include/SDL2/SDL.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) return -1;
}
and error:
PS C:\Users\Olex7\OneDrive\Pulpit\Game> make
gcc -c -g src/main.c -o src/main.o
gcc src/main.o -g -o build/game
src/main.o: In function `SDL_main':
C:\Users\Olex7\OneDrive\Pulpit\Game/src/main.c:7: undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:7: build/game] Error 1
I am having a opencv code in C:
#ifdef _CH_
#pragma package <opencv>
#endif
#ifndef _EiC
// motion templates sample code
#include "cv.h"
#include "highgui.h"
#include <time.h>
#include <math.h>
#include <ctype.h>
#include <stdio.h>
#endif
with these header files.
if I run it using
gcc `pkg-config --cflags --libs opencv` motempl_temp.c -o opencv
I get error:
/tmp/cc2rKXbX.o: In function `cvDecRefData':
motempl_temp.c:(.text+0xac2): undefined reference to `cvFree_'
motempl_temp.c:(.text+0xb4b): undefined reference to `cvFree_'
/tmp/cc2rKXbX.o: In function `cvGetRow':
motempl_temp.c:(.text+0xc63): undefined reference to `cvGetRows'
/tmp/cc2rKXbX.o: In function `cvGetCol':
motempl_temp.c:(.text+0xc91): undefined reference to `cvGetCols'
/tmp/cc2rKXbX.o: In function `cvReleaseMatND':
motempl_temp.c:(.text+0xcab): undefined reference to `cvReleaseMat'
/tmp/cc2rKXbX.o: In function `cvSubS':
motempl_temp.c:(.text+0xe08): undefined reference to `cvAddS'
/tmp/cc2rKXbX.o: In function `cvCloneSeq':
motempl_temp.c:(.text+0xe5a): undefined reference to `cvSeqSlice'
/tmp/cc2rKXbX.o: In function `cvSetNew':
motempl_temp.c:(.text+0xed6): undefined reference to `cvSetAdd'
/tmp/cc2rKXbX.o: In function `cvGetSetElem':
motempl_temp.c:(.text+0xf93): undefined reference to `cvGetSeqElem'
/tmp/cc2rKXbX.o: In function `cvEllipseBox':
motempl_temp.c:(.text+0x1062): undefined reference to `cvEllipse'
/tmp/cc2rKXbX.o: In function `cvFont':
motempl_temp.c:(.text+0x10ce): undefined reference to `cvInitFont'
/tmp/cc2rKXbX.o: In function `cvReadIntByName':
motempl_temp.c:(.text+0x11d8): undefined reference to
`cvGetFileNodeByName'
/tmp/cc2rKXbX.o: In function `cvReadRealByName':
motempl_temp.c:(.text+0x1277): undefined reference to
`cvGetFileNodeByName'
/tmp/cc2rKXbX.o: In function `cvReadStringByName':
motempl_temp.c:(.text+0x1306): undefined reference to
`cvGetFileNodeByName'
/tmp/cc2rKXbX.o: In function `cvReadByName':
motempl_temp.c:(.text+0x1349): undefined reference to
`cvGetFileNodeByName'
collect2: error: ld returned 1 exit status
All the header files are in the path /usr/local/include/opencv folder and this is included in the path variable.
The OpenCV C API is deprecated. You should use the C++ API.
You can compile your code with g++:
g++ motempl_temp.c -o opencv `pkg-config opencv --cflags --libs`
When trying to compile a simple parsing program using libxml2, GCC returns this error.
/tmp/ccuq3Hc1.o: In function `main':
xmltesting.c:(.text+0x31): undefined reference to `htmlCreatePushParserCtxt'
xmltesting.c:(.text+0x50): undefined reference to `htmlCtxtReadFile'
xmltesting.c:(.text+0x64): undefined reference to `xmlDocGetRootElement'
collect2: error: ld returned 1 exit status
Code:
#include <stdio.h>
#include <libxml/HTMLparser.h>
#include <libxml/HTMLtree.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
int main()
{
htmlDocPtr doc;
htmlNodePtr org_node;
htmlNodePtr curnt_node = NULL;
htmlParserCtxtPtr parser = htmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL, 0);
doc = htmlCtxtReadFile( parser, "html.txt", NULL, 0);
org_node = xmlDocGetRootElement( parser->myDoc );
for ( curnt_node = org_node; curnt_node; curnt_node = curnt_node->next ) {
if ( curnt_node->type == XML_TEXT_NODE ) {
printf ("%s", curnt_node->content );
}
}
}
It seems to be reading the structs fine, but the functions are not to be found?
Or is something wrong with my code?
You probably simply have to tack an -lxml2 at the end of the gcc build line.
As Dietricg Epp points out in the comments, if your library has the right .pc file pkg-config is the preferred way to get the neccesary flags. You can get both compile and link flags.
$ pkg-config libxml-2.0 --cflags --libs
-I/usr/include/libxml2 -lxml2
I want make wrapper for another shared library.
elsymobileclient.h
extern void* CreateClass(void);
elsymobileclientwrapper.c
#include <AnswStruct.h>
#include <elsymobileclient.h>
void * W_CreateClass() {
return CreateClass();
}
compile:
$ gcc -I. -L. elsymobileclientwrapper.c -lelsymobileclient
/tmp/ccDxlXsd.o: In function W_CreateClass':
elsymobileclientwrapper.c:(.text+0x7): undefined reference toCreateClass'
collect2: ld returned 1 exit status
Where's 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.