#Some weird bug in C++

146 messages ยท Page 1 of 1 (latest)

astral agate
#

Something is going on, and I don't know what.

Compiler : Clang
Version : C++20

proven gustBOT
#

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.

astral agate
#

Also this

misty dome
#

std::function<void()>

astral agate
#

Same thing lol

#

I have tried anything

misty dome
#

does it compile though, could just be bad intellisense

astral agate
#

Should compile but I get another error

gloomy ice
astral agate
#
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);
misty dome
gloomy ice
#

you're intermediate so you probably alr know this, but your compiler error is always more accurate than intellisense

ruby tundra
#

sounds like the mac dev experience

astral agate
#

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

ruby tundra
#

well

#

SDL is not header only

#

I can only guess problems will happen if you try to link against it

amber needle
#

what if you remove the global namespace before calls

astral agate
#

Do I have to use Boost's library for dynamic linking now... oh god

ruby tundra
#

just don't put C libraries in their own namespace โ„ข๏ธ

#

if there was naming collision the linker will know

astral agate
#

Alright I will try something then

ruby tundra
#

also I wish we could actually do something like this
separating libraries into namespaces

astral agate
#

The namespace isn't a problem

#

The error persists

ruby tundra
#

did you perhaps ever have a using line anywhere in headers

astral agate
#

only in the first one

#

for Core.h

hazy linden
#

I suppose it might work if you do like namespace lolol { extern "C" { #include <lib.h> } }? ๐Ÿ˜„

astral agate
#

using Element = std::function<void()>;

ruby tundra
#

okay so no using namespace

astral agate
#

But I prefer this

ruby tundra
#

i heard typedef and templates dont play well

astral agate
#

yeah

#

so I went with using

hazy linden
#

there's probably still a million ways that can go wrong

ruby tundra
#

also iirc doesn't SDL already wrap itself with #ifdef __cplusplus so that's not needed?

astral agate
#

I think it does, but I did it anyways

#

and... same error

#

lol

hazy linden
#

ยฏ_(ใƒ„)_/ยฏ

astral agate
#

My Window.cpp file gets no errors when I use std::vector

#

but doing this with Surface.cpp gives me errors

#

how come

hazy linden
#

core.hpp
__CORE_H_
thonk

ruby tundra
#

sus

#

also what's in FFI.hpp

hazy linden
#

also __ is reserved ๐Ÿ˜›

astral agate
#

So I should remove the guards?

ruby tundra
#

no

astral agate
#

I learned this from CLion as it does this automatically

hazy linden
#

just the double underscores ๐Ÿ˜„

ruby tundra
#

just don't use double underscore

#

yea

ruby tundra
hazy linden
#

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)

ruby tundra
astral agate
ruby tundra
#

and how are you using SDL in surface.cpp?

astral agate
#
#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

hazy linden
#

I'd imagine maybe SDL includes some C stdlib header which includes a combined C / C++ stdlib header which breaks something somehow somewhere?

astral agate
#

Do I have to look for a C++ wrapper of SDL now...

ruby tundra
#

I have a guess

astral agate
#

yes?

ruby tundra
#

so the solution to this would be include the headers before SDL

#

or just include SDL normally man

astral agate
#

WHAT

#

I INCLUDED BEFORE

#

AND IT WORKS

#

wtf

ruby tundra
#

?

astral agate
#

okay this is strange

#

No error on this

#

I moved core.hpp on the top

#

Okay, but why is this ?

ruby tundra
#

hmmmm

#

whats in core?

astral agate
#
#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

hazy linden
#

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"

astral agate
#
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

ruby tundra
#

yeah so basically same thing as before

astral agate
#

What if I remove the FFI namespace

#

and just use SDL normally

#

let's see if that works

hazy linden
#

that should be fine

astral agate
#

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

hazy linden
#

still very cursed

#

you now probably have copies of those inline cmath functions in SDL:: ๐Ÿ˜„

astral agate
#

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
ruby tundra
#

average experience of trying to tame C

astral agate
#

I hate writing header files

hazy linden
#

it's not wrong

#

you can't define the class twice, differently

#

did you want those in core.hpp to be forward declarations?

astral agate
#

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.

ruby tundra
#

iirc you need to tell unique_ptr the destructor you want it to use if it's not just freeing memory

astral agate
#

It's just freeing memory in this case

ruby tundra
#

ohh okay

astral agate
#

Because Window has its own destructor

#
    ~Window()
    {
        FFI::SDL::SDL_DestroyWindow(s_windowHandle);
    }
#

Btw, if you find my naming conventions weird

#

s_ means state
m_ means member

#

Like this from my settings.hpp

#

Thanks a lot for the help everyone ๐Ÿ™‚

#

!close