Skip to main content
LHarr.1
Associate II
November 15, 2024
Question

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

  • November 15, 2024
  • 3 replies
  • 1103 views

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?

3 replies

PatrickF
Technical Moderator
November 15, 2024
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.NEW ! Sidekick STM32 AI agent, see here
LHarr.1
LHarr.1Author
Associate II
November 15, 2024

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
November 15, 2024

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
November 23, 2024

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.