We are currently in the process of converting the website to the new design. Some pages, like this one, are still broken. We appreciate your patience.
Handmade Network»Forums
75 posts
None
Need with a compiler warning on a shared lib
I haven't programmed in a long while, and am having trouble with a compiler warning. I'm linking to a shared library using clang and am getting the following warning:

warning: implicit declaration of function
'function_name' is invalid in C99
[-Wimplicit-function-declaration]

I have the file included above the function that calls it, so the only thing I can think of that might be causing it, is the function declarations in the shared library's include files, are all declared in the following form:

LIBNAME_API void set_window_title(const char *title);

I think I had this problem when I used Visual Studio a long time ago. I think I set a compiler setting that gave it the name of of the LIBNAME_API, but I can't remember it. How can I fix this in gcc or clang on Linux/Unix?
Mārtiņš Možeiko
2583 posts / 2 projects
Need with a compiler warning on a shared lib
Edited by Mārtiņš Možeiko on
You need to show more code. Exactly what you have. Can you reproduce warning on gcc.godbolt.org with small code snippet? For example: https://godbolt.org/g/j4vqoe
75 posts
None
Need with a compiler warning on a shared lib
Edited by Mór on
I found out what is causing it, but I don't know how to fix it, other than turn the warning off.

This link describes the problem I am having.

https://stackoverflow.com/questio...shared-library-functions-in-linux

Replace EXPORT in the code below with the LIBNAME_API I was talking about above and you get the idea.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#if defined(_MSC_VER)
    //  Microsoft 
    #define EXPORT __declspec(dllexport)
    #define IMPORT __declspec(dllimport)
#elif defined(__GNUC__)
    //  GCC
    #define EXPORT __attribute__((visibility("default")))
    #define IMPORT
#else
    //  do nothing and hope for the best?
    #define EXPORT
    #define IMPORT
    #pragma warning Unknown dynamic link import/export semantics.
#endif


In the case of the library code, they've used the do nothing option from above, but when I replaced it with the __GNUC__ option the warning remained. Sigh...

75 posts
None
Need with a compiler warning on a shared lib
Hey not to worry, it has been fixed. It was related to some #ifdefs. I passed it in with a -D<name> option. I think that was what I did with Visual Studio a few years back.