handmade.network » Forums » Need with a compiler warning on a shared lib
Mór
70 posts
#13787 Need with a compiler warning on a shared lib
5 months, 1 week ago

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?
mmozeiko
Mārtiņš Možeiko
1670 posts
1 project
#13788 Need with a compiler warning on a shared lib
5 months, 1 week ago Edited by Mārtiņš Možeiko on Dec. 18, 2017, 6:38 a.m.

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
Mór
70 posts
#13789 Need with a compiler warning on a shared lib
5 months, 1 week ago Edited by on Dec. 18, 2017, 11:21 a.m.

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

Mór
70 posts
#13792 Need with a compiler warning on a shared lib
5 months, 1 week ago

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.