Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line 59 of tsf.h #50

Open
joeladams opened this issue Jul 29, 2020 · 1 comment
Open

Line 59 of tsf.h #50

joeladams opened this issue Jul 29, 2020 · 1 comment

Comments

@joeladams
Copy link

Hi, Our team was trying to build a C++ project using tsf.h and GNU's g++ and kept getting linking errors that the functions in tsf.h were multiply defined. We traced the problem to line 59 of tsf.h:

#define TSFDEF extern

as the functions being flagged were all fully defined internally within tsf.h, not declared in tsf.h and then defined externally. We were able to fix the problem by revising line 59 as follows:

#define TSFDEF inline

Cheers,

-Joel.

@schellingb
Copy link
Owner

Hi there

If there are linker errors regarding multiple definition of function bodies of tsf.h, that means that multiple .c or .cpp files have the line

#define TSF_IMPLEMENTATION

in them.

So make sure that only one .c or .cpp file defines this macro.
Also make sure the line is not inside a header file that is included by multiple .c or .cpp files, but inside the .c or .cpp file itself.

If you absolutely cannot avoid having that define in multiple translation units across your code base (maybe a giant project with multiple libraries that are hard to control?) then you can define TSF_STATIC before including tsf.h to make the functions static.
Like this:

#define TSF_IMPLEMENTATION
#define TSF_STATIC
#include "tsf.h"

The result will be similar to your hack that sets the inline keyword on all API functions but less detrimental to the output binary code size. And you won't have to modify the tsf.h file itself. Which you're free to do, so if inline somehow works better for you, then that's also fine :-)

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants