Thread: Shared object build issue

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    865

    Shared object build issue

    Not sure if this is strictly a code problem but since it flags one of my functions I trying here 1st, admin can always move the thread if it's deemed unrelated. So I finally settled on how I want my abstracted character reading object to be like and in turn modified all my related test projects to use a shared library, only the library in question is not completing the build process, here's the output:
    Code:
    make expr.run (in directory: /media/lee/ZXUIJI_1TB/github/mc)
    cc -shared -Wall -D OUT=libnext.so  -o libnext.so next.c
    makefile:67: recipe for target 'libnext.so' failed
    /usr/bin/ld: /tmp/ccsjP35t.o: relocation R_X86_64_PC32 against symbol `nextc_validate' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: final link failed: Bad value
    collect2: error: ld returned 1 exit status
    make: *** [libnext.so] Error 1
    Compilation failed.
    And the entire header:
    Code:
    #ifndef INC_NEXT_H
    #define INC_NEXT_H
    #include "fail.h"
    
    #ifdef _WIN32
    #include <windows.h>
    #else
    #include <limits.h>
    #include <inttypes.h>
    #include <stdbool.h>
    #include <ctype.h>
    #include <string.h>
    #include <wchar.h>
    #include <uchar.h>
    #include <iconv.h>
    #include <locale.h>
    #endif
    
    #define _2STR( DATA ) #DATA
    #define TOSTR( DATA ) _2STR( DATA )
    #define _2WCS( DATA ) L#DATA
    #define TOWCS( DATA ) _2WCS( DATA )
    #define _2UTF8( DATA ) u8#DATA
    #define TOUTF8( DATA ) _2UTF8( DATA )
    #define _2UTF16( DATA ) u#DATA
    #define TOUTF16( DATA ) _2UTF16( DATA )
    #define _2UTF32( DATA ) U#DATA
    #define TOUTF32( DATA ) _2UTF32( DATA )
    
    #ifndef __char8_t_defined
    #define __char8_t_defined
    typedef uint_least8_t char8_t;
    #endif
    
    #ifndef CHAR8_MAX
    #define CHAR8_MAX UINT_LEAST8_MAX
    #endif
    
    #ifndef CHAR16_MAX
    #define CHAR16_MAX UINT_LEAST16_MAX
    #endif
    
    #ifndef CHAR32_MAX
    #define CHAR32_MAX UINT_LEAST32_MAX
    #endif
    
    typedef int (*func_nextchr )(
    	void * pointer, char8_t *c, size_t size );
    /**
     * @brief allocates/deallocates memory
     * if size == 0, then if applicable pointer should be released
     * else if pointer == NULL allocate the memory
     * else reallocate the memory with new size
    **/
    typedef int (*func_moremem )( void **pointer, size_t size );
    /**
     * @brief appends next string/characters to ctxt
     * @return 0 on success, ERANGE if not enough memory
    **/
    typedef int (*func_nextstr )(
    	void * pointer, char8_t *c, size_t *leng, size_t size );
    
    /** @brief initialise with {0}
     * @param err readonly, takes the exit code of the nextchr() parameter
     * @param p readonly, nextc() function will fill this with the value of c
     * @param c readonly, nextc() function will clear this before calling the nextchr()
     * parameter
     * @param src the source data nextchr() will take
     * @param nextchr() fills c parameter, returns relevant exit code
    **/
    #define NEXTC_C_LENG 7
    #define NEXTC_C_SIZE (NEXTC_C_LENG * sizeof(char8_t))
    typedef struct _nextc {
    	int err;
    	char8_t p[NEXTC_C_SIZE], c[NEXTC_C_SIZE];
    	void *src;
    	func_nextchr nextchr;
    } NEXTC;
    /** @brief initialise with {0}
     * @param err readonly, takes the exit code of the nextstr() parameter or moremem() parameter
     * @param p readonly, nexts() function will fill this with the value of c
     * @param c readonly, nexts() function will clear this before calling the nextstr()
     * parameter
     * @param src the source data working with, e.g FILE pointer
     * @param moremem
     * @param nexts() fills c parameter, returns relevant exit code
    **/
    #define NEXTS_INC_TXTLENG (NEXTC_C_LENG * 80)
    #define NEXTS_INC_TXTSIZE (NEXTS_INC_TXTLENG * sizeof(char8_t))
    typedef struct _nexts {
    	int err;
    	size_t size;
    	size_t plen, clen;
    	char8_t *ptxt, *ctxt;
    	void *src;
    	func_moremem moremem;
    	func_nextstr nextstr;
    } NEXTS;
    
    /** @brief Insensitive string compare with support for limiting
     * characters
     * @return returns 0 on equal or toupper(*a) - toupper(*b) when not equal
     * @example istrncmp( NULL, NULL, 0 ), istrncmp( "a", NULL, 0 ),
     * istrncmp( NULL, "b", 0 ), istrncmp( "a", "b", 2 ) are all possible
    **/
    int utfncmp( char8_t const *a, char8_t const *b, size_t limit );
    int iutfncmp( char8_t const *a, char8_t const *b, size_t limit );
    
    int nextc_validate( NEXTC *_nextc );
    int nexts_validate( NEXTS *_nexts );
    
    /** @return 0 = end of data or ignorable failure, 1 = success **/
    bool nextc( NEXTC *_nextc );
    /** @brief Loads next string from source
     * @return 0 = end of data or ignorable failure, 1 = success
     * @example nexts( &_nexts ); free( _nexts.ptxt ); free( _nexts.ctxt ); **/
    bool nexts( NEXTS *_nexts );
    
    #endif /* INC_NEXT_H */
    Any ideas on why it's flagging that one function?

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    865
    Incidently this is the code for the 2 validation functions:
    Code:
    int nextc_validate( NEXTC *_nextc ) {
    	if ( !_nextc ) return ENODATA;
    	if ( !_nextc->nextchr ) {
    		_nextc->err = EADDRNOTAVAIL;
    		return _nextc->err;
    	}
    	_nextc->err = 0;
    	return 0;
    }
    int nexts_validate( NEXTS *_nexts ) {
    	if ( !_nexts ) return ENODATA;
    	if ( !_nexts->moremem || !_nexts->nextstr ) {
    		_nexts->err = EADDRNOTAVAIL;
    		return _nexts->err;
    	}
    	_nexts->err = 0;
    	return 0;
    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,744
    Normally, I would be passing the -c option to cc as well, if compiling files to put into libraries.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    865
    ah that was it *face palms*, completely forgot that, I basicaly just copy pasted the binary commands and modified them to create the shared libraries, completly forgot to specify no linking

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to add an array of Integers to a POSIX Shared memory Object
    By new2Cprogamming in forum C Programming
    Replies: 1
    Last Post: 03-17-2018, 02:26 PM
  2. Shared object between classes
    By drawar in forum C++ Programming
    Replies: 16
    Last Post: 10-05-2014, 08:52 AM
  3. Issue with .so (Shared Object) Files
    By in_ship in forum C Programming
    Replies: 15
    Last Post: 09-16-2012, 07:57 AM
  4. Replies: 3
    Last Post: 11-22-2011, 04:06 AM
  5. Detecting path to shared object
    By dev.fb0 in forum Linux Programming
    Replies: 5
    Last Post: 04-07-2011, 04:48 PM

Tags for this Thread