Skip to main content
LHarr.1
Associate II
Nov 15, 2024 07:47 UTC
Question

Trying to compile a simple helloworld.cpp on the STM32M157C discovery kit

I am trying to cross compile a simple helloworld.cpp program.

 

#include <iostream>

int main(int argc, char** argv)
{
 std::cout << "Hello World" << std::endl;
 return 0;
}

 

The makefile is

 

PROG = helloworld
SRCS = helloworld.cpp

CLEANFILES = $(PROG)

# Add / change option in CFLAGS and LDFLAGS
CFLAGS += -Wall $(shell pkg-config --cflags gtk+-3.0)
LDFLAGS += $(shell pkg-config --libs gtk+-3.0)

all: $(PROG)

$(PROG): $(SRCS)
	$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)

clean:
	rm -f $(CLEANFILES) $(patsubst %.c,%.o, $(SRCS))

 

I have the developer package installed and I am able to compile the gtk_hello_world.c example just fine but If I try the above code it complies just fine but during the link it complains about std::cout and std::endl amoung other things related to iostream.

 

/home/lharris/STM32CubeIDE/Developer-Package/SDK/sysroots/x86_64-ostl_sdk-linux/usr/libexec/arm-ostl-linux-gnueabi/gcc/arm-ostl-linux-gnueabi/12.3.0/ld: /tmp/ccoeJuW6.o: in function `main':
/home/lharris/Projects/HelloWorld1/helloworld.cpp:5: undefined reference to `std::cout'
and so on...

 

How can I compile a simple command line program using c++ conventions or is the needed library not in the cross development tool chain?

This topic has been closed for replies.

4 replies

PatrickF
ST Employee
Nov 15, 2024 08:05 UTC
In order to give better visibility on the answered topics, please click on 'Best Answer' on the reply which solved your issue or answered your question.Tip of the day: Try Sidekick STM32 AI agent
LHarr.1
LHarr.1Author
Associate II
Nov 15, 2024 09:06 UTC

I belive the answer is yes.  I have followed the example gtk_hello_world.c and it runs just fine.  I have also compiled a simple web server using the mongoose framework.  So basic C functionality and C++ seem to work, just having a problem with using std::cout and it's ilk.  I am suspecting that the support for std::cout in a console window is just not there.

Ozone
Principal
Nov 15, 2024 09:34 UTC

I have done very little with C++ recently.

But wouldn't you need "another compiler", i.e. calling it as "g++" instead "gcc" ?

LHarr.1
LHarr.1Author
Associate II
Nov 23, 2024 05:07 UTC

I go back and double check. I think I tried g++ as well but maybe not.  If it works I’ll update this thread. Thanks for the suggestion and heads up.