Compile error using C11 Standard Libraries

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
BB Hood
DC Developer
DC Developer
Posts: 189
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Fri Mar 30, 2007 12:09 am
Has thanked: 41 times
Been thanked: 10 times

Compile error using C11 Standard Libraries

Post by BB Hood »

I'm trying to play around with the C++11 standard Libraries and Im getting a compile error I don't know how to fix. My source:

main.cpp

Code: Select all

#include <kos.h>
#include <time.h>
#include <mutex>

extern uint8 romdisk[];
KOS_INIT_ROMDISK(romdisk);

int main(int argc, char **argv) {
    pvr_init_params_t pvrInit = { {PVR_BINSIZE_0, PVR_BINSIZE_0, PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_0}, 512 * 1024};
    pvr_init(&pvrInit);

    std::mutex   d_mutex;

    return 0;
}
My Makefile:

Code: Select all

TARGET = example.elf
OBJS = main.o

all: rm-elf $(TARGET)

include $(KOS_BASE)/Makefile.rules

clean:
	-rm -f $(TARGET) $(OBJS) romdisk.*

rm-elf:
	-rm -f $(TARGET) romdisk.*

$(TARGET): $(OBJS) romdisk.o
	kos-c++ -std=c11 -o $(TARGET) $(OBJS) romdisk.o $(OBJEXTRA) -lm

romdisk.img:
	$(KOS_GENROMFS) -f romdisk.img -d romdisk -v

romdisk.o: romdisk.img
	$(KOS_BASE)/utils/bin2o/bin2o romdisk.img romdisk romdisk.o

run: $(TARGET)
	$(KOS_LOADER) $(TARGET)

dist:
	rm -f $(OBJS) romdisk.o romdisk.img
	$(KOS_STRIP) $(TARGET)
I've also tried -std=c++11

My Error:

Code: Select all

rm -f example.elf romdisk.*
kos-c++   -c main.cpp -o main.o
In file included from /opt/toolchains/dc/sh-elf/lib/gcc/sh-elf/4.7.3/../../../../sh-elf/include/c++/4.7.3/mutex:36:0,
                 from main.cpp:8:
/opt/toolchains/dc/sh-elf/lib/gcc/sh-elf/4.7.3/../../../../sh-elf/include/c++/4.7.3/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
main.cpp: In function ‘int main(int, char**)’:
main.cpp:19:5: error: ‘mutex’ is not a member of ‘std’
main.cpp:19:18: error: expected ‘;’ before ‘d_mutex’
make: *** [main.o] Error 1
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Compile error using C11 Standard Libraries

Post by BlueCrab »

C11 and C++11 are two different languages, first of all. Don't confuse the two. :wink:

Second, with what you have, all you are doing is linking with the -std=c11 flag -- which is why you're getting the compilation error you have. In your Makefile, you need to add the -std=c++11 or -std=gnu++11 flags to your compilation flags. You can do that by adding the following to the top of your Makefile:

Code: Select all

KOS_CPPFLAGS += -std=gnu++11
You don't need the -std=c11 flag at all, and you don't need anything special on the linking line anyway, as the little snippet above will take care of both linking and compiling.

That said, as the compiler is warning you there, the support for C++11 was only considered experimental at the point of the release of GCC 4.7.3, so it may not work as you might expect.
User avatar
BB Hood
DC Developer
DC Developer
Posts: 189
Joined: Fri Mar 30, 2007 12:09 am
Has thanked: 41 times
Been thanked: 10 times

Re: Compile error using C11 Standard Libraries

Post by BB Hood »

Thank you so much. It worked :) :)
Post Reply