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

  1. #1
    Registered User
    Join Date
    May 2009

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

    Hi All

    I'm trying to build a shared object (dylib), but when compiling I get the following:
    $ 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:
    #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
    $ make linux
    gcc -fPIC -c libmyconfig.c  -o libmyconfig.o
    gcc -shared -o -lc libmyconfig.o 
    ldconfig -v -n .
    .: ->
    ln -sf
    Library 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) ?


    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
    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.


  3. #3
    Registered User
    Join Date
    May 2009
    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
    The man page will say what standards (if any) the function adheres to.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    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.

    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
    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