Thread: Undefined symbols: "_strpos", referenc... (on Mac)

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    72

    Undefined symbols: "_strpos", referenc... (on Mac)

    Hi All

    I'm trying to build a shared object (dylib), but when compiling I get the following:
    Code:
    $ make
    gcc -fPIC -c libmyconfig.c  -o libmyconfig.o
    gcc -Wall -g -fast -dynamiclib -current_version 1.0 -o libmyconfig.dylib libmyconfig.o
    Undefined symbols:
      "_strpos", referenced from:
          _load_config_file in libmyconfig.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [libmyconfig.dylib] Error 1
    It has everything todo with the strpos:
    Code:
    #include <stddef.h>
    #include <stdlib.h>
    #include <regex.h>
    #include <stdio.h>
    #include <string.h>
    ....
    ...
              char line [ 128 ]; /* or other suitable maximum line size */
    	  ...   
    	  while(fgets(line, sizeof(line), fp) != NULL)
    	   { 
                  int pos = strpos(line, '=') ;
    if I remove the last line, everything compiles fine. Furthermore, on Linux I don't have any problems
    Code:
    $ make linux
    gcc -fPIC -c libmyconfig.c  -o libmyconfig.o
    gcc -shared -o libmyconfig.so.1.0 -lc libmyconfig.o 
    ldconfig -v -n .
    .:
    	libmyconfig.so.1.0 -> libmyconfig.so.1.0
    ln -sf libmyconfig.so.1.0 libmyconfig.so
    Library libmyconfig.so created
    Any suggestions what might be the problem on my mac (osx 10.5, i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465) ?

    thnx
    LuCa

    ps if more info is needed please let me know, because this problem really stopped me

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    strpos is non-standard - so you can't rely on it being available (or the same) from one system to the next.

    You could write your own version using strchr as a helper.

    gg

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    72
    thnx a lot!!!

    How can I tell if something is standard or not ?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The man page will say what standards (if any) the function adheres to.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by jeanluca View Post
    thnx a lot!!!

    How can I tell if something is standard or not ?
    Looking up the standard spec, or in most cases, the online documentation with your IDE (or similar) will tell you what standard(s) the function complies to.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    72
    thnx again!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM