dirkwillem
Posts: 10
Joined: Tue Feb 12, 2013 11:56 am

Clang++ not compiling C++ code, undefined operator new

Thu May 29, 2014 2:11 pm

Hello

I'm trying to program C++ on my Raspberry Pi. I need to use Clang because my library uses the Blocks API. But the problem is that I can't get Clang to compile a simple program:

Code: Select all

class Foo{

};

int main(){
	Foo* foo = new Foo();
}
I compile it with the following command:

Code: Select all

clang++ -lstdc++ main.cpp -o main
And then it gives me an error:

Code: Select all

/tmp/main-E0E0nf.o: In function `main':
main.cpp:(.text+0x18): undefined reference to `operator new(unsigned long)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does anyone know how to solve this?

User avatar
teh_orph
Posts: 346
Joined: Mon Jan 30, 2012 2:09 pm
Location: London
Contact: Website

Re: Clang++ not compiling C++ code, undefined operator new

Thu May 29, 2014 2:43 pm

Aren't linker objects resolved right-to-left? If you put the -lstdc++ on the right do you get the same thing?

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Clang++ not compiling C++ code, undefined operator new

Thu May 29, 2014 2:55 pm

teh_orph wrote:Aren't linker objects resolved right-to-left? If you put the -lstdc++ on the right do you get the same thing?
Right idea; wrong terminology.

Things are resolved left-to-right - in a single pass (no back-tracking). The model is "eat only if you need to". I.e., each time a library object is encountered, the linker looks at its list of things that need to be resolved and scans the library object to see if the library object can resolve any of those things that need resolving. Generally, this means that the biggest things need to be at the end.

Which is a little un=intuitive, but that's the way it has always been.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
teh_orph
Posts: 346
Joined: Mon Jan 30, 2012 2:09 pm
Location: London
Contact: Website

Re: Clang++ not compiling C++ code, undefined operator new

Thu May 29, 2014 4:05 pm

Ah, a handy explanation! Does that apply to just libraries or what if you have 'loose' object files too?
(eg I've always found that loose object files need to have all their undef symbols connected up, but if that was within an unreferenced object file within a library then there would be no problem)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Clang++ not compiling C++ code, undefined operator new

Thu May 29, 2014 4:12 pm

Right. A .o file listed on the command line needs to be fulfilled, but a .o file found in a library (conventionally, either a .a or a .so file) serves as a fulfiller, not a fulfillee.

Note that a .c file listed on the command line is effectively the same thing as a .o file (unless the -c option was supplied).
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

enhering
Posts: 2
Joined: Wed Nov 26, 2014 3:51 pm

Re: Clang++ not compiling C++ code, undefined operator new

Wed Nov 26, 2014 4:00 pm

Hi. I have a similar problem. I can compile individual c++ files into .o files, but when I invoke g++ to link them to the main file I receive the following errors:
[email protected] ~/mms $ make



Compiling for RASPBIAN
GPIBServer
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-14+rpi1' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.6.3 (Debian 4.6.3-14+rpi1)
COLLECT_GCC_OPTIONS='-mabi=aapcs-linux' '-fPIE' '-w' '-v' '-I' 'src/classes' '-I' 'src/classes/if' '-I' 'src/classes/inst' '-I' 'src/classes/base' '-I' 'src/classes/exp' '-I' 'src/classes/base_instruments' '-I' '/usr/local/include' '-I' '/usr/local/include/libxml2' '-I' '/usr/local/include/' '-I' '/usr/local/include' '-o' 'bin/GPIBServer' '-shared-libgcc' '-march=armv6' '-mfloat-abi=hard' '-mfpu=vfp'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/cc1plus -quiet -v -I src/classes -I src/classes/if -I src/classes/inst -I src/classes/base -I src/classes/exp -I src/classes/base_instruments -I /usr/local/include -I /usr/local/include/libxml2 -I /usr/local/include/ -I /usr/local/include -imultilib . -imultiarch arm-linux-gnueabihf -D_GNU_SOURCE src/executables/GPIBServer.cpp -quiet -dumpbase GPIBServer.cpp -mabi=aapcs-linux -march=armv6 -mfloat-abi=hard -mfpu=vfp -auxbase GPIBServer -w -version -fPIE -o /tmp/cc8n2Old.s
GNU C++ (Debian 4.6.3-14+rpi1) version 4.6.3 (arm-linux-gnueabihf)
compiled by GNU C version 4.6.3, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
GGC heuristics: --param ggc-min-expand=55 --param ggc-min-heapsize=47855
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabihf"
ignoring nonexistent directory "/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/include"
ignoring nonexistent directory "src/classes/inst"
ignoring duplicate directory "/usr/local/include"
as it is a non-system directory that duplicates a system directory
ignoring nonexistent directory "/usr/local/include/libxml2"
ignoring duplicate directory "/usr/local/include/"
as it is a non-system directory that duplicates a system directory
ignoring duplicate directory "/usr/local/include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
src/classes
src/classes/if
src/classes/base
src/classes/exp
src/classes/base_instruments
/usr/include/c++/4.6
/usr/include/c++/4.6/arm-linux-gnueabihf/.
/usr/include/c++/4.6/backward
/usr/lib/gcc/arm-linux-gnueabihf/4.6/include
/usr/local/include
/usr/lib/gcc/arm-linux-gnueabihf/4.6/include-fixed
/usr/include/arm-linux-gnueabihf
/usr/include
End of search list.
GNU C++ (Debian 4.6.3-14+rpi1) version 4.6.3 (arm-linux-gnueabihf)
compiled by GNU C version 4.6.3, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
GGC heuristics: --param ggc-min-expand=55 --param ggc-min-heapsize=47855
Compiler executable checksum: 64a5da90acce21afabe8e916f286e44e
COLLECT_GCC_OPTIONS='-mabi=aapcs-linux' '-fPIE' '-w' '-v' '-I' 'src/classes' '-I' 'src/classes/if' '-I' 'src/classes/inst' '-I' 'src/classes/base' '-I' 'src/classes/exp' '-I' 'src/classes/base_instruments' '-I' '/usr/local/include' '-I' '/usr/local/include/libxml2' '-I' '/usr/local/include/' '-I' '/usr/local/include' '-o' 'bin/GPIBServer' '-shared-libgcc' '-march=armv6' '-mfloat-abi=hard' '-mfpu=vfp'
as -march=armv6 -mfloat-abi=hard -mfpu=vfp -meabi=5 -o /tmp/ccWSuWXr.o /tmp/cc8n2Old.s
COMPILER_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.6/:/usr/lib/gcc/arm-linux-gnueabihf/4.6/:/usr/lib/gcc/arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.6/:/usr/lib/gcc/arm-linux-gnueabihf/
LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.6/:/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../:/lib/arm-linux-gnueabihf/:/lib/:/usr/lib/arm-linux-gnueabihf/:/usr/lib/
COLLECT_GCC_OPTIONS='-mabi=aapcs-linux' '-fPIE' '-w' '-v' '-I' 'src/classes' '-I' 'src/classes/if' '-I' 'src/classes/inst' '-I' 'src/classes/base' '-I' 'src/classes/exp' '-I' 'src/classes/base_instruments' '-I' '/usr/local/include' '-I' '/usr/local/include/libxml2' '-I' '/usr/local/include/' '-I' '/usr/local/include' '-o' 'bin/GPIBServer' '-shared-libgcc' '-march=armv6' '-mfloat-abi=hard' '-mfpu=vfp'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/collect2 --sysroot=/ --build-id --no-add-needed --eh-frame-hdr -dynamic-linker /lib/ld-linux-armhf.so.3 -X --hash-style=both -m armelf_linux_eabi -o bin/GPIBServer /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crti.o /usr/lib/gcc/arm-linux-gnueabihf/4.6/crtbegin.o -L/usr/lib/gcc/arm-linux-gnueabihf/4.6 -L/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf -L/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../.. -L/lib/arm-linux-gnueabihf -L/usr/lib/arm-linux-gnueabihf /tmp/ccWSuWXr.o bin/o/Logger.o bin/o/TCPServer.o bin/o/FileUtils.o bin/o/PrologixGPIB.o bin/o/GPIBd.o -lncurses -lstdc++ -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/arm-linux-gnueabihf/4.6/crtend.o /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crtn.o
bin/o/TCPServer.o: In function `TCPServer::TCPServer()':
src/classes/TCPServer.cpp:(.text+0x74): undefined reference to `operator new(unsigned long)'
bin/o/PrologixGPIB.o: In function `PrologixGPIB::PrologixGPIB()':
src/classes/if/PrologixGPIB.cpp:(.text+0x68): undefined reference to `operator new(unsigned long)'
src/classes/if/PrologixGPIB.cpp:(.text+0xd8): undefined reference to `operator new[](unsigned long)'
bin/o/GPIBd.o: In function `GPIBd::GPIBd()':
src/classes/GPIBd.cpp:(.text+0x7c): undefined reference to `operator new(unsigned long)'
src/classes/GPIBd.cpp:(.text+0xb4): undefined reference to `operator new(unsigned long)'
bin/o/GPIBd.o: In function `GPIBd::SetInterfaceType(GPIBInterfaceType)':
src/classes/GPIBd.cpp:(.text+0x364): undefined reference to `operator new(unsigned long)'
collect2: ld returned 1 exit status
GNUmakefile:234: recipe for target 'bin/GPIBServer' failed
make: *** [bin/GPIBServer] Error 1
[email protected] ~/mms $
Any idea how can I solve this?

My makefile is:

Code: Select all

#************************************************************************
#                                                                       *
#  This file is part of Multi Measuremendt System (MMS)                 *
#  Copyright (C) 2013  Eduardo Novaes Hering                            *
#                                                                       *
#  Multi Measurement System is free software: you can redistribute      *
#  it and/or modify it under the terms of the GNU General Public        *
#  License as published by the Free Software Foundation, either         *
#  version 3 of the License, or(at your option) any later version.      *
#                                                                       *
#  This program is distributed in the hope that it will be useful,      *
#  but WITHOUT ANY WARRANTY; without even the implied warranty of       *
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
#  GNU General Public License for more details.                         *
#                                                                       *
#  You should have received a copy of the GNU General Public License    *
#  along with this program.  If not, see <http://www.gnu.org/licenses/> *
#                                                                       *
#************************************************************************

CLASSES_SRC_DIR=src/classes
EXEC_SRC_DIR=src/executables
CGIDIR=src/cgi
BINDIR=bin
OBJDIR=$(BINDIR)/o

ifneq ($(wildcard FREEBSD),)
  OS=FREEBSD
endif
ifneq ($(wildcard MACOS),)
  OS=MACOS
endif
ifneq ($(wildcard RASPBIAN),)
  OS=RASPBIAN
endif

ifeq ($(OS),MACOS)
  COMPILER=llvm-g++ -w 
  ICGICC=-I/usr/include
  LCGICC=-L/usr/lib -L/Users/enhering/tmp/cgicc-3.2.12/cgicc/.libs -lcgicc

  IGSL=-I/opt/local/include/
  LGSL=-L/opt/local/lib -lgsl

  IMGL=-I/usr/local/include/
  LMGL=-L/usr/local/lib -lmgl

  IXML=-I/opt/local/include/libxml2
  LXML=-L/opt/local/lib -lxml2
  
  DOCUMENT_ROOT=~/Sites/mms
  CGI_BIN=~/Sites/
endif

ifeq ($(OS),FREEBSD)
  COMPILER=clang++ -w
  ICGICC=-I/usr/local/include
  LCGICC=-L/usr/local/lib -lcgicc

  IGSL=-I/usr/local/include/
  LGSL=-L/usr/local/lib -lgsl

  IMGL=-I/usr/local/include
  LMGL=-L/usr/local/lib -lmgl

  IXML=-I/usr/local/include/libxml2
  LXML=-L/usr/local/lib -lxml2

  DOCUMENT_ROOT=/usr/home/$(USERNAME)/public_html
  CGI_BIN=/usr/home/$(USERNAME)/public_html
endif

ifeq ($(OS),RASPBIAN)
  COMPILER=g++ -mabi=aapcs-linux -fPIE -w -v
  ICGICC=-I/usr/local/include
  LCGICC=-L/usr/local/lib -lcgicc

  IGSL=-I/usr/local/include/
  LGSL=-L/usr/local/lib -lgsl

  IMGL=-I/usr/local/include
  LMGL=-L/usr/local/lib -lmgl

  IXML=-I/usr/local/include/libxml2
  LXML=-L/usr/local/lib -lxml2

  DOCUMENT_ROOT=/usr/home/$(USERNAME)/public_html
  CGI_BIN=/usr/home/$(USERNAME)/public_html
endif

INCLUDES=-Isrc/classes -Isrc/classes/if -Isrc/classes/inst -Isrc/classes/base -Isrc/classes/exp -Isrc/classes/base_instruments $(ICGICC) $(IXML) $(IGSL) $(IMGL)

HGURL=ssh://xp-dev.com/multi-measurement-system

all: space os $(BINDIR)/GPIBServer $(BINDIR)/Example  done count

experimental: $(OBJDIR)/MMSProtocol.o $(BINDIR)/ProtocolTest

os:
	@echo 'Compiling for '$(OS)

done:
	@echo "done."
  
space:
	@echo ''
	@echo ''
	@echo ''

#EXPERIMENTAL CODE

$(OBJDIR)/MMSProtocol.o: $(CLASSES_SRC_DIR)/exp/MMSProtocol.cpp $(CLASSES_SRC_DIR)/exp/MMSProtocol.h 
	@echo 'Experimental MMSProtocol.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/exp/MMSProtocol.cpp $(INCLUDES) -o $(OBJDIR)/MMSProtocol.o

$(OBJDIR)/Parser.o: $(CLASSES_SRC_DIR)/exp/Parser.cpp $(CLASSES_SRC_DIR)/exp/Parser.h $(OBJDIR)/Lexer.o
	@echo 'Experimental Parser.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/exp/Parser.cpp $(INCLUDES) -o $(OBJDIR)/Parser.o

$(OBJDIR)/Lexer.o: $(CLASSES_SRC_DIR)/exp/Lexer.cpp $(CLASSES_SRC_DIR)/exp/Lexer.h $(OBJDIR)/Token.o
	@echo 'Experimental Lexer.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/exp/Lexer.cpp $(INCLUDES) -o $(OBJDIR)/Lexer.o

$(OBJDIR)/Token.o: $(CLASSES_SRC_DIR)/exp/Token.cpp $(CLASSES_SRC_DIR)/exp/Token.h
	@echo 'Experimental Token.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/exp/Token.cpp $(INCLUDES) -o $(OBJDIR)/Token.o

# TESTED CODE

$(BINDIR)/ProtocolTest: $(EXEC_SRC_DIR)/ProtocolTest.cpp $(EXEC_SRC_DIR)/ProtocolTest.h $(OBJDIR)/MMSProtocol.o $(OBJDIR)/MMSClass.o $(OBJDIR)/FileUtils.o
	@echo 'ProtocolTest'
	@$(COMPILER) $(EXEC_SRC_DIR)/ProtocolTest.cpp             \
							 $(OBJDIR)/MMSProtocol.o 											\
							 $(OBJDIR)/MMSClass.o 												\
							 $(OBJDIR)/MMSError.o 												\
							 $(OBJDIR)/MMSConfig.o                        \
							 $(OBJDIR)/Logger.o                           \
							 $(OBJDIR)/FileUtils.o                        \
							 $(INCLUDES) $(LXML) -lncurses                \
							 -o $(BINDIR)/ProtocolTest

$(BINDIR)/CreateCalibTable: $(EXEC_SRC_DIR)/CreateCalibTable.cpp $(EXEC_SRC_DIR)/CreateCalibTable.h
	@echo 'CreateCalibTable'
	@$(COMPILER) $(EXEC_SRC_DIR)/CreateCalibTable.cpp $(INCLUDES) -o $(BINDIR)/CreateCalibTable

$(BINDIR)/Setup1: $(EXEC_SRC_DIR)/Setup1.cpp $(EXEC_SRC_DIR)/Setup1.h $(OBJDIR)/CryoCon62.o $(OBJDIR)/FileUtils.o
	@echo 'Setup1'
	@$(COMPILER) $(EXEC_SRC_DIR)/Setup1.cpp  \
               $(OBJDIR)/FileUtils.o       \
               $(OBJDIR)/Logger.o          \
               $(OBJDIR)/TCPClient.o       \
               $(OBJDIR)/GPIBInstrument.o  \
               $(OBJDIR)/CryoCon62.o       \
               $(INCLUDES)                 \
               -o $(BINDIR)/Setup1

$(CGIDIR)/TempControllerCGI.cgi: $(EXEC_SRC_DIR)/TempControllerCGI.cpp $(EXEC_SRC_DIR)/TempControllerCGI.h $(OBJDIR)/MMSCGI.o $(OBJDIR)/GenTempControllerCGI.o
	@echo 'TempControllerCGI.cgi'
	@$(COMPILER) $(EXEC_SRC_DIR)/TempControllerCGI.cpp  \
               $(OBJDIR)/ConfigTempController.o       \
               $(OBJDIR)/GenTempControllerCGI.o       \
               $(OBJDIR)/MMSCGI.o                     \
               $(INCLUDES) $(LCGICC) $(LMGL) $(LXML)  \
               -o $(CGIDIR)/TempControllerCGI.cgi

$(BINDIR)/TempController: $(EXEC_SRC_DIR)/TempController.cpp $(EXEC_SRC_DIR)/TempController.h $(OBJDIR)/GenTempController.o $(OBJDIR)/ConfigTempController.o
	@echo 'TempController'
	@$(COMPILER) $(EXEC_SRC_DIR)/TempController.cpp  \
               $(OBJDIR)/ConfigTempController.o    \
               $(OBJDIR)/GenTempController.o       \
               $(INCLUDES) $(LXML)                 \
              -o $(BINDIR)/TempController





$(OBJDIR)/CryoCon62.o: $(CLASSES_SRC_DIR)/inst/CryoCon62.cpp $(CLASSES_SRC_DIR)/inst/CryoCon62.h $(OBJDIR)/GPIBInstrument.o
	@echo 'CryoCon62.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/inst/CryoCon62.cpp $(INCLUDES) -o $(OBJDIR)/CryoCon62.o



$(OBJDIR)/GenTempControllerCGI.o: $(CLASSES_SRC_DIR)/GenTempControllerCGI.cpp $(CLASSES_SRC_DIR)/GenTempControllerCGI.h $(OBJDIR)/ConfigTempController.o
	@echo 'GenTempControllerCGI.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/GenTempControllerCGI.cpp $(INCLUDES) $(LXML) $(LGS) $(LMGL) $(LCGICC) -o $(OBJDIR)/GenTempControllerCGI.o

$(OBJDIR)/MMSCGI.o: $(CLASSES_SRC_DIR)/MMSCGI.cpp $(CLASSES_SRC_DIR)/MMSCGI.h
	@echo 'MMSCGI.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/MMSCGI.cpp $(INCLUDES) $(LMGL) $(LCGICC) -o $(OBJDIR)/MMSCGI.o



$(OBJDIR)/GenTempController.o: $(CLASSES_SRC_DIR)/GenTempController.cpp $(CLASSES_SRC_DIR)/GenTempController.h $(OBJDIR)/ConfigTempController.o
	@echo 'GenTempController.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/GenTempController.cpp $(INCLUDES) $(LXML) -o $(OBJDIR)/GenTempController.o

$(OBJDIR)/ConfigTempController.o: $(CLASSES_SRC_DIR)/ConfigTempController.cpp $(CLASSES_SRC_DIR)/ConfigTempController.h
	@echo 'ConfigTempController.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/ConfigTempController.cpp $(INCLUDES) $(LXML) -o $(OBJDIR)/ConfigTempController.o


$(BINDIR)/Example: $(EXEC_SRC_DIR)/Example.cpp $(EXEC_SRC_DIR)/Example.h $(OBJDIR)/MMSInstrument.o
	@echo 'Example'
	@$(COMPILER) $(EXEC_SRC_DIR)/Example.cpp     \
               $(OBJDIR)/Logger.o              \
	             $(OBJDIR)/MMSError.o            \
               $(OBJDIR)/MMSConfig.o           \
               $(OBJDIR)/FileUtils.o           \
               $(OBJDIR)/MMSClass.o 		       \
               $(OBJDIR)/TCPClient.o           \
               $(OBJDIR)/GPIBInstrument.o      \
               $(OBJDIR)/MMSInstrument.o       \
               $(INCLUDES) $(LXML)             \
               -lncurses                       \
               -o $(BINDIR)/Example

$(OBJDIR)/MMSInstrument.o: $(CLASSES_SRC_DIR)/base_instruments/MMSInstrument.cpp $(CLASSES_SRC_DIR)/base_instruments/MMSInstrument.h $(OBJDIR)/GPIBInstrument.o
	@echo 'MMSInstrument.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/base_instruments/MMSInstrument.cpp $(INCLUDES) -o $(OBJDIR)/MMSInstrument.o
	
$(OBJDIR)/GPIBInstrument.o: $(CLASSES_SRC_DIR)/base_instruments/GPIBInstrument.cpp $(CLASSES_SRC_DIR)/base_instruments/GPIBInstrument.h $(OBJDIR)/MMSClass.o $(OBJDIR)/TCPClient.o
	@echo 'GPIBInstrument.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/base_instruments/GPIBInstrument.cpp $(INCLUDES) -o $(OBJDIR)/GPIBInstrument.o
	
$(OBJDIR)/TCPClient.o: $(CLASSES_SRC_DIR)/TCPClient.cpp $(CLASSES_SRC_DIR)/TCPClient.h $(OBJDIR)/MMSClass.o
	@echo 'TCPClient.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/TCPClient.cpp $(INCLUDES) -o $(OBJDIR)/TCPClient.o


$(BINDIR)/GPIBServer: $(EXEC_SRC_DIR)/GPIBServer.cpp $(EXEC_SRC_DIR)/GPIBServer.h $(OBJDIR)/GPIBd.o $(OBJDIR)/FileUtils.o
	@echo 'GPIBServer'
	@$(COMPILER) $(EXEC_SRC_DIR)/GPIBServer.cpp  \
               $(OBJDIR)/Logger.o              \
               $(OBJDIR)/TCPServer.o           \
               $(OBJDIR)/FileUtils.o           \
               $(OBJDIR)/PrologixGPIB.o        \
               $(OBJDIR)/GPIBd.o               \
               $(INCLUDES)                     \
               -lncurses                       \
               -o $(BINDIR)/GPIBServer         \
               -lstdc++                        \

$(OBJDIR)/GPIBd.o: $(CLASSES_SRC_DIR)/GPIBd.cpp $(CLASSES_SRC_DIR)/GPIBd.h $(OBJDIR)/TCPServer.o $(OBJDIR)/PrologixGPIB.o
	@echo 'GPIBd.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/GPIBd.cpp $(INCLUDES) -DUSEPROLOGIXGPIB=1 -o $(OBJDIR)/GPIBd.o

$(OBJDIR)/TCPServer.o: $(CLASSES_SRC_DIR)/TCPServer.cpp $(CLASSES_SRC_DIR)/TCPServer.h $(OBJDIR)/Logger.o
	@echo 'TCPServer.o'
	@$(COMPILER) $(RASP_PI) -c $(CLASSES_SRC_DIR)/TCPServer.cpp $(INCLUDES) -o $(OBJDIR)/TCPServer.o

$(OBJDIR)/PrologixGPIB.o: $(CLASSES_SRC_DIR)/if/PrologixGPIB.cpp $(CLASSES_SRC_DIR)/if/PrologixGPIB.h
	@echo 'PrologixGPIB.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/if/PrologixGPIB.cpp $(INCLUDES) -o $(OBJDIR)/PrologixGPIB.o


$(OBJDIR)/MMSClass.o: $(CLASSES_SRC_DIR)/base/MMSClass.cpp $(CLASSES_SRC_DIR)/base/MMSClass.h $(OBJDIR)/Logger.o $(OBJDIR)/MMSError.o $(OBJDIR)/MMSConfig.o
	@echo 'MMSClass.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/base/MMSClass.cpp $(INCLUDES) -o $(OBJDIR)/MMSClass.o

$(OBJDIR)/MMSConfig.o: $(CLASSES_SRC_DIR)/base/MMSConfig.cpp $(CLASSES_SRC_DIR)/base/MMSConfig.h $(OBJDIR)/Logger.o $(OBJDIR)/MMSError.o
	@echo 'MMSConfig.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/base/MMSConfig.cpp $(INCLUDES) -o $(OBJDIR)/MMSConfig.o

$(OBJDIR)/MMSError.o: $(CLASSES_SRC_DIR)/base/MMSError.cpp $(CLASSES_SRC_DIR)/base/MMSError.h $(OBJDIR)/Logger.o
	@echo 'MMSError.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/base/MMSError.cpp -o $(OBJDIR)/MMSError.o

$(OBJDIR)/Logger.o: $(CLASSES_SRC_DIR)/base/Logger.cpp $(CLASSES_SRC_DIR)/base/Logger.h $(OBJDIR)/FileUtils.o
	@echo 'Logger.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/base/Logger.cpp -o $(OBJDIR)/Logger.o

$(OBJDIR)/FileUtils.o: $(CLASSES_SRC_DIR)/base/FileUtils.cpp $(CLASSES_SRC_DIR)/base/FileUtils.h
	@echo 'FileUtils.o'
	@$(COMPILER) -c $(CLASSES_SRC_DIR)/base/FileUtils.cpp -o $(OBJDIR)/FileUtils.o


clean:
	@rm -rf $(BINDIR)/GPIBServer*
	@rm -rf $(BINDIR)/CreateCalibTable*
	@rm -rf $(BINDIR)/Setup1*
	@rm -rf $(BINDIR)/ProtocolTest*
	@rm -rf $(BINDIR)/TempController*
	@rm -rf $(BINDIR)/Example*
	@rm -rf $(CGIDIR)/TempControllerCGI.cgi*
	@rm -rf $(OBJDIR)/GenTempControllerCGI.o*
	@rm -rf $(OBJDIR)/*.log
	@rm -rf $(BINDIR)/*.log
	@rm -rf bin/o/*
	@touch bin/o/OBJECT_FILES_HERE
	@rm -rf src/WebInterface/cgi/GenTempControllerCGI.cgi
	@echo "Cleaned."
  
pull:
	@hg pull $(HGURL)
	@echo "Pulled last version from repo."
	@hg update
	@echo "Updated working version."

push: 
	@hg push $(HGURL)
	@echo "Pushed current version to repo."
  
resolve-theirs-good:
	@hg resolve -t internal:other --all


install-web:
	@echo "Installing web interface:"
	@rm -rf $(DOCUMENT_ROOT)
	@rm -rf $(CGI_BIN)/*
	@mkdir $(DOCUMENT_ROOT)
	@chmod 755 $(DOCUMENT_ROOT)
	@echo "  Removed and recreated mms directory on apache server."

	@cp -Rf $(CGIDIR)/html/* $(DOCUMENT_ROOT)
	@chmod -R 755 $(DOCUMENT_ROOT)
	@cp $(CGIDIR)/css/MyStyle.css $(CGI_BIN)
	@cp $(CGIDIR)/TempControllerCGI.cgi $(CGI_BIN)
	@chmod -R 777 $(CGI_BIN)
	@echo "  Copied html files to their locations."

	@rm -f $(CGI_BIN)/logs
	@ln -s `pwd`/logs $(CGI_BIN)/logs
	@chmod -R 755 $(CGI_BIN)/logs
	@echo "  Linked logs directory to its location."

	@rm -f $(CGI_BIN)/config.xml
	@ln -s `pwd`/conf/cryocon62-1.xml $(CGI_BIN)/config.xml
	@echo "  Linked configuration files."
	@echo "Done."

count:
	@counters/increase_build_counter.sh

enhering
Posts: 2
Joined: Wed Nov 26, 2014 3:51 pm

Re: Clang++ not compiling C++ code, undefined operator new

Wed Nov 26, 2014 6:09 pm

Solved.

ARM g++ compiler apparently does not know anything about the operators new and delete. Check these references to see if you understand why:

http://www.mbedded.ninja/programming/mi ... oc-creator
http://stackoverflow.com/questions/7015 ... deletevoid

So I created a file called MMSEmbedded.cpp with the following content:

Code: Select all

#ifndef __MMSEMBEDDED_CPP_
#define __MMSEMBEDDED_CPP_

  #if ARM_PLATFORM==1

  #include <stdlib.h>

  void* operator new(size_t size) { 
    return malloc(size); 
  } 

  void operator delete(void* ptr) { 
    free(ptr); 
  }

  void * operator new[](size_t size) { 
    return malloc(size); 
  } 
 
  void operator delete[](void * ptr) { 
    free(ptr); 
  }

  #endif

#endif
and linked it to the main executable using the following call on the makefile of the post above:

Code: Select all

$(BINDIR)/GPIBServer: $(EXEC_SRC_DIR)/GPIBServer.cpp $(EXEC_SRC_DIR)/GPIBServer.h $(OBJDIR)/GPIBd.o $(OBJDIR)/FileUtils.o $(OBJDIR)/MMSEmbedded.o
	@echo 'GPIBServer'
	@$(COMPILER) $(EXEC_SRC_DIR)/GPIBServer.cpp  \
	             $(OBJDIR)/MMSEmbedded.o         \
               $(OBJDIR)/Logger.o              \
               $(OBJDIR)/TCPServer.o           \
               $(OBJDIR)/FileUtils.o           \
               $(OBJDIR)/PrologixGPIB.o        \
               $(OBJDIR)/GPIBd.o               \
               $(INCLUDES)                     \
               -lncurses                       \
               -o $(BINDIR)/GPIBServer         
And now it is compiling on Raspberry Pi.

Thanks for your attention. I hope this helps.

Return to “C/C++”