Jump to content

Problems with msp430-g++

Recommended Posts

So I'm trying to to create a simple little program that will interface with an si570 I2C-controlled variable oscillator. The code that I started with as a library was originally for an mbed platform [1]. Opting to keep the class structure from the mbed library, I proceeded to use the included msp430-g++ compiler shipped with Energia.


I knocked up a quick Makefile based upon this thread here [2]:

OBJECTS = main.o SI570.o
CC = msp430-g++
CPPFLAGS =-Os -Wall -g -mmcu=msp430g2553

all : $(OBJECTS)
  $(CC) $(CPPFLAGS) $(OBJECTS) -o main.elf

%.o : %.cpp
  $(CC) $(CPPFLAGS) -c $<

  rm -fr $(OBJECTS) main.elf

  mspdebug tilib -d USB --force-reset "prog main.elf"

    msp430-size main.elf

So when I exercise make, I get the error of the linker not finding -lstdc++


If I add -nodefaultlibs to my CFLAGS, I got a metric crap ton of math library functions not being 

msp430-g++ -Os -Wall -g -mmcu=msp430g2553 -nodefaultlibs -lm -lc -lgcc -c main.cpp
msp430-g++ -Os -Wall -g -mmcu=msp430g2553 -nodefaultlibs -lm -lc -lgcc -c SI570.cpp
SI570.cpp: In member function 'void SI570::get_registers()':
SI570.cpp:76:24: warning: suggest parentheses around comparison in operand of '&
' [-Wparentheses]
SI570.cpp:53:7: warning: unused variable 'i' [-Wunused-variable]
msp430-g++ -Os -Wall -g -mmcu=msp430g2553 -nodefaultlibs -lm -lc -lgcc main.o SI570.o -o main.elf
SI570.o: In function `SI570::get_registers()': SI570.cpp:(.text+0x26e): undefined reference to `__floatsisf' SI570.cpp:(.text+0x278): undefined reference to `__mulsf3' SI570.cpp:(.text+0x27c): undefined reference to `__fixunssfsi' SI570.cpp:(.text+0x280): undefined reference to `__floatunsisf' SI570.cpp:(.text+0x296): undefined reference to `__floatsisf' SI570.cpp:(.text+0x2a0): undefined reference to `__mulsf3' SI570.cpp:(.text+0x2ac): undefined reference to `__addsf3' SI570.cpp:(.text+0x2b0): undefined reference to `__fixunssfsi' SI570.cpp:(.text+0x2c0): undefined reference to `__floatunsisf' SI570.cpp:(.text+0x2ca): undefined reference to `__mulsf3' SI570.cpp:(.text+0x2fc): undefined reference to `__floatsisf' SI570.cpp:(.text+0x308): undefined reference to `__addsf3'  


I've tried differing combinations of the combination of -lm -lc -lgcc per a couple of stackoverflow posts [3], but nothing really seemed to change. Does anyone have any pointers for me on how to link this feller?


As an aside, I dropped the following bat file into the bin directory and when launched, it automatically adds the path for the compiler and msp430-debug. I found it convenient:



@echo off
rem This file is the script to set path for mspgcc tool chain.

set TL_PATH=%~dp0
set PATH=%TL_PATH%;%PATH%;%TL_PATH%\..\mspdebug
cmd /K cd %CD% 

[1] - http://mbed.org/users/soldeerridder/code/SI570/

[2] - http://forum.43oh.com/topic/835-makefile-for-mspgcc/

[3] - http://stackoverflow.com/questions/6534191/undefined-reference-to-only-some-math-h-functions

Link to post
Share on other sites

Okay, so I tried reworking it using C-style structs and msp430-gcc instead of msp430-g++; basically I'm getting the same results if I try use floor and ceil from math.h; if I remove the --nodefaultlibs from my CFLAGS, I then get an error about floor and ceil not being defined. If I get slimy and use my own version of floor and ceil by using casting of ints, it actually compiles. So I know I'm missing something basic in the original problem. Does anyone have any insight as to what I bombed on during my linking and the missing math functions? I think I'm going to try and use nm and see if floor and ceil actually are defined somewhere....

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...