error (.text+0x *) undefined reference to ' ' need help

This is a discussion on error (.text+0x *) undefined reference to ' ' need help within the C Programming forums, part of the General Programming Boards category; Hey so basically I'm trying to get a huge amount of code to compile. None of them are main files ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    error (.text+0x *) undefined reference to ' ' need help

    Hey so basically I'm trying to get a huge amount of code to compile. None of them are main files so I added a main into thats basically blank
    Code:
    #include <stdio>
    
    int main( int ....., char**   .....) {
    
    printf(hi\n);
    }
    the main might be wrong but thats not the problem so all the other code uses functions from different folders.
    /root/Desktop/Vmainline/fctl/
    fctl.c
    uses a function from Vmain/v2lin_v02/lib
    like semGive();

    so i use the command
    gcc -I../../v2lin_v02/lib -I/root/Desktop/VMainlineV3/h -lm -o main *.c *.h -L../../v2lin_v02/lib

    and i get a whole bunch of errors basically looking like this
    fctl.c.text+0x16a): undefined reference to `semGive'

    and i know theres some kind of link cuz without the -I../../ v2lin.......... blah blah i would actually get a error saying
    semGive() undeclared or something
    so is there another way to link it or am i missing something And i even loaded the library from
    v2lin_v02/lib by


    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/Desktop/VMainlineV3/v2lin_v02/lib

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    Who wrote the "huge amount of code"? You might want to ask the author for help, read documentation, etc. If you wrote it, then I think that we should start by helping you fix your code, since at a glance it probably has alot of errors.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Where is semGive() implemented? Is there a .c file somewhere, or is it in a library?
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    semGive() is like under
    semlib.c
    and a header for it is
    semlib.h

    and thats in VmainV3/ v2lin_v02/lib
    both of them
    and im compiling in VmainV3/fabric/fctl

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Well that's your problem then. You probably need to compile the code in VmainV3/v2lin_v02/lib to a library, and then link to that library when you compile what's in fctl.
    bit∙hub [bit-huhb] n. A source and destination for information.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So, do you have a libsem.a, or a semlib.o, or something? If all you have is a .c file, then you need to compile it just like you compile everything else. If you have a .a file, you need to add the library with -lsem (or whatever the thing is called).

  7. #7
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    okay so i do compile the code in that lib directory i get a libv2lin.so libv2linmain.so


    then i just do
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/Desktop/VMainlineV3/v2lin_v02/lib

    and it works fine cuz i had a test folder
    /root/Desktop/VMainV3/v2lin_v02/samples/with_main


    and in that folder it had a program with_main.c and it compiled and
    ldd with_main

    linux-vdso.so.1 => (0x00007fff3bfff000)
    libv2lin.so => /root/Desktop/VMainlineV3/v2lin_v02/lib/libv2lin.so (0x00007fc333b68000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc33394c000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fc333748000)
    librt.so.1 => /lib64/librt.so.1 (0x00007fc33353f000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fc3331e6000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fc333d75000)

  8. #8
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    i get a semLib.o in the v2lin_v02/lib

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21