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

Add missing STBIRDEF to allow multiple stb_image_resize2.h implementations #1739

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rcurtin
Copy link

@rcurtin rcurtin commented Jan 23, 2025

The following code that includes the STB image resize implementation in multiple files will fail:

a.cpp:

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#define STB_IMAGE_RESIZE_STATIC
#include "stb_image_resize2.h"

int a()
{
  return 3;
}

b.cpp:

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#define STB_IMAGE_RESIZE_STATIC
#include "stb_image_resize2.h"

int b()
{
  return 2;
}

main.cpp:

int a();
int b();

int main()
{
  return a() + b();
}

Compile with

g++ -o main main.cpp a.cpp b.cpp

and you get

/usr/bin/ld: /tmp/cciFeflx.o:(.data+0x420): multiple definition of `stbir__s32_32768'; /tmp/cctlLRFu.o:(.data+0x420): first defined here
/usr/bin/ld: /tmp/cciFeflx.o:(.data+0x430): multiple definition of `stbir__s16_32768'; /tmp/cctlLRFu.o:(.data+0x430): first defined here
collect2: error: ld returned 1 exit status

The fix is easy: just a missing STBIRDEF in front of some simd constant variables, so that they are defined with static and can be included in multiple translation units if STB_IMAGE_RESIZE_STATIC is defined. Once the fix in this PR is applied, the test program links happily.

Thanks so much for STB! We use it inside of mlpack to provide image support for machine learning tasks.

@jeffrbig2
Copy link

Dang, thought I had them all - I'll probably do this on my end, since I need to do it for all the different SIMD versions...

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

Successfully merging this pull request may close these issues.

2 participants