cancel
Showing results for 
Search instead for 
Did you mean: 

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

LHarr.1
Associate II

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?

2 REPLIES 2
PatrickF
ST Employee

Hi @LHarr.1 

have you looked to https://wiki.st.com/stm32mpu/wiki/Cross-compile_with_OpenSTLinux_SDK#Adding_Linux_user_space_applications ?

Regards.

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.
LHarr.1
Associate II

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.