Can't use the same function name in 2 different extension?

I have 2 extensions, when building it praised error:

ld.lld: error: duplicate symbol: Initialize()
>>> defined at expo_android.cpp:15 (upload/_expo/src/expo_android.cpp:15)
>>>            expo_android.cpp_34.o:(Initialize()) in archive /tmp/job8053469848410713987/build/libExpo_35.a
>>> defined at device_android.cpp:26 (upload/_device/src/device_android.cpp:26)
>>>            device_android.cpp_31.o:(.text._Z10Initializev+0x0) in archive /tmp/job8053469848410713987/build/libDevice_32.a

Does it mean I can’t use the same function name in 2 different extension?

It seems adding namespace would resolve it.
Is there anyway to avoid conflicts without adding namespace?

That’s a common constraint for most programming languages, that you cannot have two public functions with the same name.

In C/C++, you can make the function private to your compile unit, by setting the work “static” in front of it:

static void MyFunction() {}

That way, it will only be visible within that compile unit (e.g. the .cpp file), and you may avoid that linker error.

1 Like

I thought our engine has a way to manage it so that each extension is an individual one. Thanks for the “static”, I’m quite new to C++ :smiley:


We use regular C/C++ tools to build, and that’s part of the learning curve :slight_smile: