Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, This is a small test case I wrote in which I can't understand why I have an undefined reference. I have an undefined reference which I thought only requires ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    4

    undefined reference

    Hi,

    This is a small test case I wrote in which I can't understand why I have an undefined reference. I have an undefined reference which I thought only requires linking w/ the libs that contain this symbol, which I am. The function dm_connect() is in the library libdm, and this is on the g++ command line when I compile as shown. The libdm is a C library and I'm calling this in my C++ program.

    Can anyone help me understand what I'm doing wrong?

    --- Compile and Error

    $ g++ $(pkg-config --cflags glib-2.0) -I/usr/include -I/usr/local/include -I/home/joe/Projects/net-1.0/util -L/usr/local/lib -L/home/joe/Projects/net-1.0/libdm $(pkg-config --libs glib-2.0) -ldm main.cpp
    /tmp/ccksTRGA.o: In function `main':
    main.cpp.text+0x30): undefined reference to `dm_connect(char*, unsigned short)'
    collect2: ld returned 1 exit status

    --- Source
    #include <stdio.h>

    #include "gxclient.h"

    using namespace std;

    int main ()
    {
    int fd = -1;

    uint16_t port = 11002;

    char *dmhostname = "localhost";

    fd = dm_connect(dmhostname, port);

    if (fd < 0) {
    printf("failed\n");
    }

    return 0;
    }

  2. #2
    Just Joined!
    Join Date
    Feb 2010
    Posts
    2

    Developer Libraries

    You may need the developer libraries and not the standard ones. Try obtaining libdm-dev in addition to libdm, which will probably be needed for developer builds.

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Also, since this is a C-linkage function used in a C++ program, you need to make sure that you have declared the function as extern "C" either directly, or enclosing it and other C declarations inside a
    Code:
    #ifdef __cplusplus
    extern "C" {
    #endif
    .
    .
    .
    #ifdef __cplusplus
    }
    #endif
    block.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...