#Some weird bug in C++
146 messages ยท Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
Also this
std::function<void()>
does it compile though, could just be bad intellisense
Should compile but I get another error
show the compile error
error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/stdlib.h:143:10: error: no member named 'ldiv' in the global namespace; did you mean simply 'ldiv'?
return ::ldiv(__x, __y);
^~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/stdlib.h:149:9: note: 'ldiv' declared here
ldiv_t ldiv(long, long) __pure2;
^
In file included from Source/Modules/Core/Surface.cpp:1:
In file included from Source/Modules/Core/../Imported/FFI.hpp:5:
In file included from /usr/local/include/SDL2/SDL.h:32:
In file included from /usr/local/include/SDL2/SDL_main.h:25:
In file included from /usr/local/include/SDL2/SDL_stdinc.h:46:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/stdlib.h:148:10: error: no member named 'lldiv' in the global namespace; did you mean simply 'lldiv'?
return ::lldiv(__x, __y);
^~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/stdlib.h:153:10: note: 'lldiv' declared here
lldiv_t lldiv(long long, long long);

you're intermediate so you probably alr know this, but your compiler error is always more accurate than intellisense
sounds like the mac dev experience
I have a suspicion that this is an error because SDL is a C library which I tried to import within a namespace
So that I have a separate namespace for every library in C that I use if so
So that there is nothing like a possible function name overlap
well
SDL is not header only
I can only guess problems will happen if you try to link against it
what if you remove the global namespace before calls
Do I have to use Boost's library for dynamic linking now... oh god
just don't put C libraries in their own namespace โข๏ธ
if there was naming collision the linker will know
Alright I will try something then
also I wish we could actually do something like this
separating libraries into namespaces
did you perhaps ever have a using line anywhere in headers
I suppose it might work if you do like namespace lolol { extern "C" { #include <lib.h> } }? ๐
using Element = std::function<void()>;
okay so no using namespace
Theoretically, I can even do typedef
But I prefer this
i heard typedef and templates dont play well
Good point I will try
there's probably still a million ways that can go wrong
also iirc doesn't SDL already wrap itself with #ifdef __cplusplus so that's not needed?
ยฏ_(ใ)_/ยฏ
My Window.cpp file gets no errors when I use std::vector
but doing this with Surface.cpp gives me errors
how come
core.hpp
__CORE_H_

also __ is reserved ๐
So I should remove the guards?
no
I learned this from CLion as it does this automatically
just the double underscores ๐
adding UB to your code one header guard at a time
underscore followed by capitcal letter is also reserved, IIRC
and anything with a leading underscore in the global namespace?
(not that I'd expect this to be the actual problem)
this might be the trouble maker
#ifndef _H_FFI
#define _H_FFI
namespace Droplet::FFI
{
namespace SDL
{
extern "C" {
#include <SDL2/SDL.h>
}
} // namespace SDL
} // namespace Droplet::FFI
#endif
and how are you using SDL in surface.cpp?
#include "../Imported/FFI.hpp"
#include "core.hpp"
#include <memory>
#include <vector>
namespace Droplet
{
class Surface
{
private:
Window* m_Owner{};
std::vector<Element> m_Elements{};
public:
Surface()
{
m_Owner = nullptr;
}
explicit Surface(Window &refOwner)
{
m_Owner = &refOwner;
}
~Surface() {
delete m_Owner;
};
};
} // namespace Droplet
Still no SDL calls
I'd imagine maybe SDL includes some C stdlib header which includes a combined C / C++ stdlib header which breaks something somehow somewhere?
Do I have to look for a C++ wrapper of SDL now...
I have a guess
yes?
wait he mentioned it lol
so the solution to this would be include the headers before SDL
or just include SDL normally man
?
okay this is strange
No error on this
I moved core.hpp on the top
Okay, but why is this ?
#ifndef _CORE_H
#define _CORE_H
#include <functional>
namespace Droplet
{
using Element = std::function<void>;
class Window
{
};
class Surface
{
};
} // namespace Droplet
#endif // _CORE_H
And suddently
std::function
is also working
when i moved this shit
what the fuck
This is cursed
Wait so
Okay
oh, I have an idea
scrolling through a few SDL headers, it looks like they forward declare some external stuff
that might break when it's now in namespace SDL
hence the errors about "lol what's ::whatever, did you mean whatever"
error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/math.h:792:91: error: no member named 'acosf' in the global namespace; did you mean simply 'acosf'?
inline _LIBCPP_INLINE_VISIBILITY float acos(float __lcpp_x) _NOEXCEPT {return ::acosf(__lcpp_x);}
^~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/math.h:308:14: note: 'acosf' declared here
extern float acosf(float);
^
In file included from Source/Modules/Core/Surface.cpp:2:
In file included from Source/Modules/Core/../Imported/FFI.hpp:9:
In file included from /usr/local/include/SDL2/SDL.h:32:
In file included from /usr/local/include/SDL2/SDL_main.h:25:
In file included from /usr/local/include/SDL2/SDL_stdinc.h:90:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/math.h:793:91: error: no member named 'acosl' in the global namespace; did you mean simply 'acosl'?
inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return ::acosl(__lcpp_x);}
^~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/math.h:310:20: note: 'acosl' declared here
extern long double acosl(long double);
^
> in Source/Modules/Core/Surface.cpp
Another error now
What if I remove the FFI namespace
and just use SDL normally
let's see if that works
that should be fine
if it works, then whatever
SDL names are prefixed with SDL_
so I don't care as much
wait hold up
I saw
the error was
because i had this
and then I did
I guess include order matters
lol
so yay, I can have namespaces
coolio
still very cursed
you now probably have copies of those inline cmath functions in SDL:: ๐
This is the error I get now, but I know the problem.
[ 20%]: cache compiling.release Source/Modules/Core/Window.cpp
[ 20%]: cache compiling.release Source/Modules/Core/Surface.cpp
error: Source/Modules/Core/Surface.cpp:9:7: error: redefinition of 'Surface'
class Surface
^
Source/Modules/Core/core.hpp:13:7: note: previous definition is here
class Surface
^
1 error generated.
> in Source/Modules/Core/Surface.cpp
average experience of trying to tame C
I hate writing header files
it's not wrong
you can't define the class twice, differently
did you want those in core.hpp to be forward declarations?
Yes I know, I had just done class Something {}; instead of class Something;
And now I realised
I have to make a prototype of every fucking function in the class
Because I get this (since the type is incomplete, as there are no declarations in the header)
Is there a way to automake headers?
Or is it always hand by hand?
Meanwhile I swapped to smart pointers.
iirc you need to tell unique_ptr the destructor you want it to use if it's not just freeing memory
It's just freeing memory in this case
ohh okay
