I'm playing around with XPC, GCD and go but I hit a quick wall when my code was failing to compile with the following error messages (which I don't understand):
main(__DATA/__const): unexpected reloc for dynamic symbol _NSConcreteGlobalBlock
main(__DATA/__const): unhandled relocation for _NSConcreteGlobalBlock (type 28 rtype 120)
I am compiling using go build the code that follows:
main.go
package main
/*
#include <xpc/xpc.h>
#include "wrapper.h"
*/
import "C"
import (
"fmt"
)
//export HandleXPCEvent
func HandleXPCEvent(event C.xpc_object_t) {
fmt.Println("Event was handled")
}
func main() {
name := C.CString("com.example.xpc")
queue := C.dispatch_queue_create(name, nil)
conn := C.xpc_connection_create(name, queue)
C.set_event_handler(conn)
//C.xpc_connection_resume(conn)
}
wrapper.h
#ifndef _WRAPPER_H_
#define _WRAPPER_H_
#include <stdlib.h>
#include <stdio.h>
#include <xpc/xpc.h>
xpc_connection_t connect( char* name);
void set_event_handler(xpc_connection_t connection);
#endif
wrapper.c
#include "wrapper.h"
#include <dispatch/dispatch.h>
extern void HandleXPCEvent(xpc_object_t);
xpc_connection_t connect( char* name) {
dispatch_queue_t queue = dispatch_queue_create(name,0);
return xpc_connection_create(name,queue);
}
void set_event_handler(xpc_connection_t connection) {
xpc_connection_set_event_handler(connection, ^(xpc_object_t event) {
xpc_retain(event);
// Call Go function
HandleXPCEvent(event);
});
}
I'm I doing something wrong? Is this some kind of go bug or how can this be fixed?
Update:
I ran go build -x -work on my project and I got the following output:
➣ go build -x -work
WORK=/var/folders/fb/bgfqk8wx5x16w7yh2cg50vrw0000gn/T/go-build524335717
mkdir -p $WORK/github.com/gabrielayuso/go-xpc/_obj/
mkdir -p $WORK/github.com/gabrielayuso/go-xpc/_obj/exe/
cd /Users/gabrielayuso/Documents/Workspace/Projects/go/src/github.com/gabrielayuso/go-xpc
/usr/local/go/pkg/tool/darwin_amd64/cgo -objdir $WORK/github.com/gabrielayuso/go-xpc/_obj/ -- -I $WORK/github.com/gabrielayuso/go-xpc/_obj/ main.go
/usr/local/go/pkg/tool/darwin_amd64/6c -F -V -w -I $WORK/github.com/gabrielayuso/go-xpc/_obj/ -I /usr/local/go/pkg/darwin_amd64 -o $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_defun.6 -D GOOS_darwin -D GOARCH_amd64 $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_defun.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -print-libgcc-file-name
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/github.com/gabrielayuso/go-xpc/_obj/ -o $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_main.o -c $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_main.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/github.com/gabrielayuso/go-xpc/_obj/ -o $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_export.o -c $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_export.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/github.com/gabrielayuso/go-xpc/_obj/ -o $WORK/github.com/gabrielayuso/go-xpc/_obj/main.cgo2.o -c $WORK/github.com/gabrielayuso/go-xpc/_obj/main.cgo2.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/github.com/gabrielayuso/go-xpc/_obj/ -o $WORK/github.com/gabrielayuso/go-xpc/_obj/wrapper.o -c ./wrapper.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_.o $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_main.o $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_export.o $WORK/github.com/gabrielayuso/go-xpc/_obj/main.cgo2.o $WORK/github.com/gabrielayuso/go-xpc/_obj/wrapper.o
/usr/local/go/pkg/tool/darwin_amd64/cgo -objdir $WORK/github.com/gabrielayuso/go-xpc/_obj/ -dynimport $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_.o -dynout $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_import.c
/usr/local/go/pkg/tool/darwin_amd64/6c -F -V -w -I $WORK/github.com/gabrielayuso/go-xpc/_obj/ -I /usr/local/go/pkg/darwin_amd64 -o $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_import.6 -D GOOS_darwin -D GOARCH_amd64 $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_import.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/github.com/gabrielayuso/go-xpc/_obj/_all.o $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_export.o $WORK/github.com/gabrielayuso/go-xpc/_obj/main.cgo2.o $WORK/github.com/gabrielayuso/go-xpc/_obj/wrapper.o -Wl,-r -nostdlib /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/x86_64/libgcc.a
/usr/local/go/pkg/tool/darwin_amd64/6g -o $WORK/github.com/gabrielayuso/go-xpc/_obj/_go_.6 -p github.com/gabrielayuso/go-xpc -D _/Users/gabrielayuso/Documents/Workspace/Projects/go/src/github.com/gabrielayuso/go-xpc -I $WORK $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_gotypes.go $WORK/github.com/gabrielayuso/go-xpc/_obj/main.cgo1.go
/usr/local/go/pkg/tool/darwin_amd64/pack grcP $WORK $WORK/github.com/gabrielayuso/go-xpc.a $WORK/github.com/gabrielayuso/go-xpc/_obj/_go_.6 $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_import.6 $WORK/github.com/gabrielayuso/go-xpc/_obj/_cgo_defun.6 $WORK/github.com/gabrielayuso/go-xpc/_obj/_all.o
cd .
/usr/local/go/pkg/tool/darwin_amd64/6l -o $WORK/github.com/gabrielayuso/go-xpc/_obj/exe/a.out -L $WORK $WORK/github.com/gabrielayuso/go-xpc.a
# github.com/gabrielayuso/go-xpc
main(__DATA/__const): unexpected reloc for dynamic symbol _NSConcreteGlobalBlock
main(__DATA/__const): unhandled relocation for _NSConcreteGlobalBlock (type 28 rtype 120)
Content of $WORK dir as generated by go build -x -work: go-xpc_work.zip
I'm not very familiar with compiling and linking therefore I can't make much sense of this output. I just noticed that _cgo_import.c a file generated by cgo (with options -dynimport and -dynout) has #pragma cgo_import_dynamic _NSConcreteGlobalBlock _NSConcreteGlobalBlock "" in the first line which is related to the error message the linker gave.
Hope this information can help to find out what the problem is and how to solve it.
I don't know much about those libraries but nothing jumps out at me with the code you have here.
Some useful debug output can be obtained from go build -x -work which will print the commands and the working directory for you.
The working directory will be left untouched so you can go look at the code cgo generates for you. That plus the commands it will print for you should get you started on tracking down the problem.
I have a wrapper written up for using Go and XPC in Cocoa Applications.
It's located here:
https://github.com/aventurella/go-xpc
Related
I have taken the code from the following source on Github and am trying to run it from Qt on RHEL Red Hat 4.4.7-17:
https://github.com/neveraway/oclJPEGDecoder
I extracted the project folder and ran qmake -projectin it. I opened the files in Qt creator and further modified my .pro file to link OpenCL sources and add the CXX and CFLAGS.
My .pro file looks like this:
######################################################################
# Automatically generated by qmake (1.07a) Tue Mar 28 14:51:49 2017
######################################################################
TEMPLATE = app
DEPENDPATH += src \
/usr/local/cuda-7.0/lib64/
INCLUDEPATH += . src \
/usr/local/cuda-7.0/lib64/\
/usr/local/cuda-7.0/include/
# Input
HEADERS += src/bitstream.h \
src/bmp.h \
src/decoder.h \
src/huffman.h \
src/idct.h \
src/jpeg.h \
src/macro.h \
src/stdafx.h \
src/targetver.h \
src/zigzag.h
SOURCES += src/bitstream.cpp \
src/cpuIDCT8x8.cpp \
src/decoder.cpp \
src/huffman.cpp \
src/main.cpp \
src/oclDCT8x8.cpp \
src/parser.cpp \
src/stdafx.cpp \
src/main.cpp
LIBS += -L/usr/local/cuda-7.0/lib64/ -lOpenCL
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CFLAGS += -std=c99
DISTFILES += \
src/idct8x8.cl \
oclJPEGDecoder.sln \
oclJPEGDecoder.vcxproj \
oclJPEGDecoder.vcxproj.filters \
README.md \
test/JPEG_example_JPG_RIP_050.jpg
When I clicked on Run qmake and then Build All, this is what I saw under "Compile Output":
18:08:23: Configuration unchanged, skipping qmake step.
18:08:23: Starting: "/usr/bin/make"
Makefile:634: warning: overriding commands for target `main.o'
Makefile:603: warning: ignoring old commands for target `main.o'
g++ -c -pipe -std=c++11 -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../oclJPEGDecoder-master -I. -I../oclJPEGDecoder-master -I../oclJPEGDecoder-master/src -I/usr/local/cuda-7.0/lib64 -I/usr/local/cuda-7.0/include -I/opt/Qt5.6.2/5.6/gcc_64/include -I/opt/Qt5.6.2/5.6/gcc_64/include/QtGui -I/opt/Qt5.6.2/5.6/gcc_64/include/QtCore -I. -I/opt/Qt5.6.2/5.6/gcc_64/mkspecs/linux-g++ -o bitstream.o ../oclJPEGDecoder-master/src/bitstream.cpp
cc1plus: error: unrecognized command line option "-std=c++11"
make: *** [bitstream.o] Error 1
18:08:23: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project oclJPEGDecoder-master (kit: Desktop Qt 5.6.2 GCC 64bit)
When executing step "Make"
18:08:23: Elapsed time: 00:00.
My Makefile has the following contents:
#############################################################################
# Makefile for building: oclJPEGDecoder-master
# Generated by qmake (3.0) (Qt 5.6.2)
# Project: ../oclJPEGDecoder-master/oclJPEGDecoder-master.pro
# Template: app
# Command: /opt/Qt5.6.2/5.6/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ../oclJPEGDecoder-master/oclJPEGDecoder-master.pro
#############################################################################
MAKEFILE = Makefile
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB
CFLAGS = -pipe -g -Wall -W -D_REENTRANT -fPIC $(DEFINES)
CXXFLAGS = -pipe -std=c++11 -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC $(DEFINES)
INCPATH = -I../oclJPEGDecoder-master -I. -I../oclJPEGDecoder-master -I../oclJPEGDecoder-master/src -I/usr/local/cuda-7.0/lib64 -I/usr/local/cuda-7.0/include -I/opt/Qt5.6.2/5.6/gcc_64/include -I/opt/Qt5.6.2/5.6/gcc_64/include/QtGui -I/opt/Qt5.6.2/5.6/gcc_64/include/QtCore -I. -I/opt/Qt5.6.2/5.6/gcc_64/mkspecs/linux-g++
QMAKE = /opt/Qt5.6.2/5.6/gcc_64/bin/qmake
DEL_FILE = rm -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
COPY = cp -f
COPY_FILE = cp -f
COPY_DIR = cp -f -R
INSTALL_FILE = install -m 644 -p
INSTALL_PROGRAM = install -m 755 -p
INSTALL_DIR = cp -f -R
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
TAR = tar -cf
COMPRESS = gzip -9f
DISTNAME = oclJPEGDecoder-master1.0.0
DISTDIR = /root/Downloads/build-oclJPEGDecoder-master-Desktop_Qt_5_6_2_GCC_64bit-Debug/.tmp/oclJPEGDecoder-master1.0.0
LINK = g++
LFLAGS = -Wl,-rpath,/opt/Qt5.6.2/5.6/gcc_64/lib
LIBS = $(SUBLIBS) -L/usr/local/cuda-7.0/lib64/ -lOpenCL -L/opt/Qt5.6.2/5.6/gcc_64/lib -lQt5Gui -L/usr/lib64 -lQt5Core -lGL -lpthread
AR = ar cqs
RANLIB =
SED = sed
STRIP = strip
My .o files look like this:
####### Compile
bitstream.o: ../oclJPEGDecoder-master/src/bitstream.cpp ../oclJPEGDecoder-master/src/stdafx.h \
../oclJPEGDecoder-master/src/targetver.h \
../oclJPEGDecoder-master/src/macro.h \
../oclJPEGDecoder-master/src/bitstream.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o bitstream.o ../oclJPEGDecoder-master/src/bitstream.cpp
cpuIDCT8x8.o: ../oclJPEGDecoder-master/src/cpuIDCT8x8.cpp ../oclJPEGDecoder-master/src/stdafx.h \
../oclJPEGDecoder-master/src/targetver.h \
../oclJPEGDecoder-master/src/macro.h \
../oclJPEGDecoder-master/src/idct.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o cpuIDCT8x8.o ../oclJPEGDecoder-master/src/cpuIDCT8x8.cpp
decoder.o: ../oclJPEGDecoder-master/src/decoder.cpp ../oclJPEGDecoder-master/src/stdafx.h \
../oclJPEGDecoder-master/src/targetver.h \
../oclJPEGDecoder-master/src/macro.h \
../oclJPEGDecoder-master/src/jpeg.h \
../oclJPEGDecoder-master/src/bmp.h \
../oclJPEGDecoder-master/src/bitstream.h \
../oclJPEGDecoder-master/src/huffman.h \
../oclJPEGDecoder-master/src/zigzag.h \
../oclJPEGDecoder-master/src/idct.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o decoder.o ../oclJPEGDecoder-master/src/decoder.cpp
huffman.o: ../oclJPEGDecoder-master/src/huffman.cpp ../oclJPEGDecoder-master/src/stdafx.h \
../oclJPEGDecoder-master/src/targetver.h \
../oclJPEGDecoder-master/src/macro.h \
../oclJPEGDecoder-master/src/huffman.h \
../oclJPEGDecoder-master/src/bitstream.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o huffman.o ../oclJPEGDecoder-master/src/huffman.cpp
main.o: ../oclJPEGDecoder-master/src/main.cpp ../oclJPEGDecoder-master/src/stdafx.h \
../oclJPEGDecoder-master/src/targetver.h \
../oclJPEGDecoder-master/src/macro.h \
../oclJPEGDecoder-master/src/bitstream.h \
../oclJPEGDecoder-master/src/huffman.h \
../oclJPEGDecoder-master/src/idct.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../oclJPEGDecoder-master/src/main.cpp
oclDCT8x8.o: ../oclJPEGDecoder-master/src/oclDCT8x8.cpp ../oclJPEGDecoder-master/src/stdafx.h \
../oclJPEGDecoder-master/src/targetver.h \
/usr/local/cuda-7.0/include/CL/opencl.h \
/usr/local/cuda-7.0/include/CL/cl.h \
/usr/local/cuda-7.0/include/CL/cl_platform.h \
/usr/local/cuda-7.0/include/CL/cl_gl.h \
/usr/local/cuda-7.0/include/CL/cl_gl_ext.h \
/usr/local/cuda-7.0/include/CL/cl_ext.h \
../oclJPEGDecoder-master/src/macro.h \
../oclJPEGDecoder-master/src/idct.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o oclDCT8x8.o ../oclJPEGDecoder-master/src/oclDCT8x8.cpp
parser.o: ../oclJPEGDecoder-master/src/parser.cpp ../oclJPEGDecoder-master/src/stdafx.h \
../oclJPEGDecoder-master/src/targetver.h \
../oclJPEGDecoder-master/src/macro.h \
../oclJPEGDecoder-master/src/jpeg.h \
../oclJPEGDecoder-master/src/decoder.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o parser.o ../oclJPEGDecoder-master/src/parser.cpp
stdafx.o: ../oclJPEGDecoder-master/src/stdafx.cpp ../oclJPEGDecoder-master/src/stdafx.h \
../oclJPEGDecoder-master/src/targetver.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o stdafx.o ../oclJPEGDecoder-master/src/stdafx.cpp
main.o: ../oclJPEGDecoder-master/src/main.cpp ../oclJPEGDecoder-master/src/stdafx.h \
../oclJPEGDecoder-master/src/targetver.h \
../oclJPEGDecoder-master/src/macro.h \
../oclJPEGDecoder-master/src/bitstream.h \
../oclJPEGDecoder-master/src/huffman.h \
../oclJPEGDecoder-master/src/idct.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../oclJPEGDecoder-master/src/main.cpp
####### Install
install: FORCE
uninstall: FORCE
FORCE:
2nd ATTEMPT WITH -std=c++0x:
I changed the CXX_FLAGS command to QMAKE_CXXFLAGS += -std=c++0x and kept everything else unchanged in my .pro file.
When I clicked on Build All after making the change, this is the output I got under "Compile Output":
18:38:06: Running steps for project oclJPEGDecoder-master...
18:38:06: Configuration unchanged, skipping qmake step.
18:38:06: Starting: "/usr/bin/make"
Makefile:634: warning: overriding commands for target `main.o'
Makefile:603: warning: ignoring old commands for target `main.o'
g++ -c -pipe -std=c++0x -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../oclJPEGDecoder-master -I. -I../oclJPEGDecoder-master -I../oclJPEGDecoder-master/src -I/usr/local/cuda-7.0/lib64 -I/usr/local/cuda-7.0/include -I/opt/Qt5.6.2/5.6/gcc_64/include -I/opt/Qt5.6.2/5.6/gcc_64/include/QtGui -I/opt/Qt5.6.2/5.6/gcc_64/include/QtCore -I. -I/opt/Qt5.6.2/5.6/gcc_64/mkspecs/linux-g++ -o bitstream.o ../oclJPEGDecoder-master/src/bitstream.cpp
In file included from ../oclJPEGDecoder-master/src/bitstream.cpp:4:
../oclJPEGDecoder-master/src/bitstream.h:368: error: 'nullptr' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:368: error: ISO C++ forbids initialization of member 'mBitReservoir'
../oclJPEGDecoder-master/src/bitstream.h:368: error: making 'mBitReservoir' static
../oclJPEGDecoder-master/src/bitstream.h:368: error: invalid in-class initialization of static data member of non-integral type 'uint8_t*'
../oclJPEGDecoder-master/src/bitstream.h:369: error: ISO C++ forbids initialization of member 'mCapacity'
../oclJPEGDecoder-master/src/bitstream.h:369: error: making 'mCapacity' static
../oclJPEGDecoder-master/src/bitstream.h:369: error: ISO C++ forbids in-class initialization of non-const static member 'mCapacity'
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::free()':
../oclJPEGDecoder-master/src/bitstream.h:96: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:96: error: 'nullptr' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:98: error: type '<type error>' argument given to 'delete', expected pointer
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::trim()':
../oclJPEGDecoder-master/src/bitstream.h:110: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'bool BitStream::reserve(size_t)':
../oclJPEGDecoder-master/src/bitstream.h:137: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'bool BitStream::frontBit() const':
../oclJPEGDecoder-master/src/bitstream.h:209: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint8_t BitStream::frontFullByte() const':
../oclJPEGDecoder-master/src/bitstream.h:214: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::front9b(uint8_t) const':
../oclJPEGDecoder-master/src/bitstream.h:219: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::front17b(uint8_t) const':
../oclJPEGDecoder-master/src/bitstream.h:227: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::front25b(uint8_t) const':
../oclJPEGDecoder-master/src/bitstream.h:235: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::writeBit(bool)':
../oclJPEGDecoder-master/src/bitstream.h:246: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h:248: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'const uint8_t* BitStream::frontData() const':
../oclJPEGDecoder-master/src/bitstream.h:307: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'uint32_t BitStream::cachedFrontBits(int)':
../oclJPEGDecoder-master/src/bitstream.h:340: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.h: In member function 'void BitStream::moveDataTo(uint8_t*)':
../oclJPEGDecoder-master/src/bitstream.h:398: error: 'mBitReservoir' was not declared in this scope
../oclJPEGDecoder-master/src/bitstream.cpp: In member function 'size_t BitStream::append(const uint8_t*, size_t)':
../oclJPEGDecoder-master/src/bitstream.cpp:22: error: 'mBitReservoir' was not declared in this scope
make: *** [bitstream.o] Error 1
18:38:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project oclJPEGDecoder-master (kit: Desktop Qt 5.6.2 GCC 64bit)
When executing step "Make"
18:38:06: Elapsed time: 00:00.
I got errors in bitstream.c due to incompatibility with the compiler.
How can I get around this issue? Do I absolutely need to install a new version of g++ to get this code to work? Do I need to include anything in my Makefile?
Please guide me in this matter.
EDIT:
My output for g++ --version:
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I typed yum install rpmdevtools rpm-build and it gave me the following response:
Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, security,
: subscription-manager
Setting up Install Process
Package rpmdevtools-7.5-2.el6.noarch already installed and latest version
Package rpm-build-4.8.0-55.el6.x86_64 already installed and latest version
Nothing to do
I wanted to obtain more information about gcc on my system so I typed this command:
yum list available |grep gcc
It gave me this response:
compat-gcc-34.x86_64 3.4.6-19.el6 rhel-6-workstation-rpms
compat-gcc-34-c++.x86_64 3.4.6-19.el6 rhel-6-workstation-rpms
compat-gcc-34-g77.x86_64 3.4.6-19.el6 rhel-6-workstation-rpms
gcc-gnat.x86_64 4.4.7-18.el6 rhel-6-workstation-rpms
gcc-java.x86_64 4.4.7-18.el6 rhel-6-workstation-rpms
gcc-objc.x86_64 4.4.7-18.el6 rhel-6-workstation-rpms
gcc-objc++.x86_64 4.4.7-18.el6 rhel-6-workstation-rpms
Your 4.4.7 version of gcc is too old to fully enable C++11 features.
You need to upgrade the compiler to a version superior to 4.6 ( at least ) or if it's possible for you, upgrade your distro (let's say RHEL 7) which includes a more recent compiler.
When compiling ltrace with icecc we run into a compilation problem. This is the minimal example:
main.c
#include <assert.h>
int main(int argc, char **argv) {
assert(argc != argc);
return 0;
}
test.sh:
#!/bin/bash
set -x
# one step compilation (no warning)
gcc -Wall main.c
# splitted compilation (warning)
gcc -Wall -E main.c -o main.i
gcc -Wall --preprocessed main.i
output:
++ gcc -Wall main.c
++ gcc -Wall -E main.c -o main.i
++ gcc -Wall --preprocessed main.i
main.c: In function ‘main’:
main.c:4:10: warning: self-comparison always evaluates to false [-Wtautological-compare]
assert(argc != argc);
^~
As you can see the result is different when compiling in one step and when preprocessing and compiling in two steps. Is this intended behavior?
I use gcc 6.3, the issue also appears in gcc 6.2 for ARM. I also cannot ignore this, as the full example uses -Werror.
Currently, I make a project with scons.
I compiled source codes and it is time to link them.
However, I got an error that ld cannot find object files.
The SConscript is located in src/kernel32, and
import os, sys
# Compile CPP
env_gpp_options = {
'CXX' : 'x86_64-pc-linux-g++',
'CXXFLAGS' : '-std=c++11 -g -m32 -ffreestanding -fno-exceptions -fno-rtti',
'LINK' : 'x86_64-pc-linux-ld',
'LINKFLAGS' : '-melf_i386 -T scripts/elf_i386.x -nostdlib -e main -Ttext 0x10200',
}
env_gpp = Environment(**env_gpp_options)
env_gpp.Append(ENV = {'PATH' : os.environ['PATH']})
object_cpp_list = Glob('*.cpp')
for object_cpp in object_cpp_list:
env_gpp.Object(object_cpp)
# Find all object file
object_target_list = Glob('*.o')
# Linking
env_link_target = 'kernel32.elf'
env_gpp.Program(env_link_target, object_target_list)
and message I got is
x86_64-pc-linux-g++ -o build/kernel32/cpu.o -c -std=c++11 -g -m32 -ffreestanding -fno-exceptions -fno-rtti src/kernel32/cpu.cpp
x86_64-pc-linux-g++ -o build/kernel32/main.o -c -std=c++11 -g -m32 -ffreestanding -fno-exceptions -fno-rtti src/kernel32/main.cpp
x86_64-pc-linux-g++ -o build/kernel32/memory.o -c -std=c++11 -g -m32 -ffreestanding -fno-exceptions -fno-rtti src/kernel32/memory.cpp
x86_64-pc-linux-g++ -o build/kernel32/pageManager.o -c -std=c++11 -g -m32 -ffreestanding -fno-exceptions -fno-rtti src/kernel32/pageManager.cpp
x86_64-pc-linux-g++ -o build/kernel32/utils.o -c -std=c++11 -g -m32 -ffreestanding -fno-exceptions -fno-rtti src/kernel32/utils.cpp
x86_64-pc-linux-ld -o build/kernel32/kernel32.elf -melf_i386 -T scripts/elf_i386.x -nostdlib -e main -Ttext 0x10200 build/kernel32/asmUtils.o build/kernel32/cpu.o build/kernel32/main.o build/kernel32/memory.o build/kernel32/pageManager.o build/kernel32/utils.o
x86_64-pc-linux-ld: cannot find main.o
scons: *** [build/kernel32/kernel32.elf] Error 1
scons: building terminated because of errors.
I checked the directory, build/kernel32/, and I found main.o file.
What is my mistake?
Is there an way to change working directory for scons?
Please let me know what I missed.
You can try this:
import os, sys
# Compile CPP
env_gpp_options = {
'CXX' : 'x86_64-pc-linux-g++',
'CXXFLAGS' : '-std=c++11 -g -m32 -ffreestanding -fno-exceptions -fno-rtti',
'LINK' : 'x86_64-pc-linux-ld',
'LINKFLAGS' : '-melf_i386 -T scripts/elf_i386.x -nostdlib -e main -Ttext 0x10200',
}
env_gpp = Environment(**env_gpp_options)
env_gpp.Append(ENV = {'PATH' : os.environ['PATH']})
object_cpp_list = Glob('*.cpp')
object_target_list = []
for object_cpp in object_cpp_list:
object_target_list.extend(env_gpp.Object(object_cpp))
# Linking
env_link_target = 'kernel32.elf'
env_gpp.Program(env_link_target, object_target_list)
Or
import os, sys
# Compile CPP
env_gpp_options = {
'CXX' : 'x86_64-pc-linux-g++',
'CXXFLAGS' : '-std=c++11 -g -m32 -ffreestanding -fno-exceptions -fno-rtti',
'LINK' : 'x86_64-pc-linux-ld',
'LINKFLAGS' : '-melf_i386 -T scripts/elf_i386.x -nostdlib -e main -Ttext 0x10200',
}
env_gpp = Environment(**env_gpp_options)
env_gpp.Append(ENV = {'PATH' : os.environ['PATH']})
object_cpp_list = Glob('*.cpp')
# Linking
env_link_target = 'kernel32.elf'
env_gpp.Program(env_link_target, object_cpp_list)
This is full scons scripts.
In project root directory,
#SConstruct
build_dir = 'build'
# Build
SConscript(['src/SConscript'], variant_dir = build_dir, duplicate = 0)
# Clean
Clean('.', build_dir)
In src directory
#SConscript for src
SConscript(['bootloader/SConscript',
'kernel32/SConscript'])
In kernel32 directory
#SConscript for kernel32
import os, sys
# Build entry
env_entry = Environment(tools=['default', 'nasm'])
target_entry = 'entry.bin'
object_entry = 'entry.s'
output_entry = env_entry.Object(target_entry, object_entry)
# Compile CPP
env_gpp_options = {
'CXX' : 'x86_64-pc-linux-g++',
'CXXFLAGS' : '-std=c++11 -g -m32 -ffreestanding -fno-exceptions -fno-rtti',
'LINK' : 'x86_64-pc-linux-ld',
'LINKFLAGS' : '-melf_i386 -T scripts/elf_i386.x -nostdlib -e main -Ttext 0x10200',
}
env_gpp = Environment(**env_gpp_options)
env_gpp.Append(ENV = {'PATH' : os.environ['PATH']})
object_cpp_list = Glob('*.cpp')
for object_cpp in object_cpp_list:
env_gpp.Object(object_cpp)
# Compile ASM
env_nasm = Environment(tools=['default', 'nasm'])
env_nasm.Append(ASFLAGS='-f elf32')
object_nasm_list = Glob('*.asm')
for object_nasm in object_nasm_list:
env_nasm.Object(object_nasm)
# Find all object file
object_target_list = Glob('*.o')
object_target_list.append('entry.bin')
# Linking
env_link_target = 'kernel32.elf'
env_gpp.Program(env_link_target, object_target_list)
Thank you for your attention.
Like two of my previous questions (inline-asm-with-gcc & arm7tdmi-does-not-support-requested-special-purpose-register, I have some build problem when converting code compiled with ARMASM to gcc(code sourcery GCC-4.6.2 eabi).
This time is at linking process: I get a lot of "first defined here" and "multiple definition" to inline functions. Example :
inline U16 ByteSwap16(U16 uData) {
return ( (uData >> 8) | (uData << 8) );
}
I get " multiple definition of `ByteSwap16' " and "first defined here" on the first line.
Here's the linking parameter that I use for the file with the error :
arm-none-eabi-ld -T".\linker.ld" -Map=BootLoad.map -o BootLoad.elf InitMain.o tsk_main.o ecp.o memalloc.o tsk_ecp.o firmdesc.o crc.o flash.o eth.o firmflash.o firmdest.o bcfg.o bootdownload.o cinit.o serial.o cpu.o mmu.o ngucos.o cdbini.o cs712sio.o cs712eth.o nginit.o MmuSdram0.o ../../OS/ngos/lib/rtstub/arm/gcc/libngosd4m32l.a ../../OS/ngip/lib/rtstub/arm/gcc/libngipd4m32l.a
In case the error comes in compilation process :
arm-none-eabi-gcc -c -H -Wall -Wa,-adhlns="tsk_main.o.lst" -fmessage-length=0 -MMD -MP -MF"tsk_main.d" -MT"tsk_main.d" -fpic -o"tsk_main.o" -march=armv4t -mcpu=arm7tdmi -mlittle-endian -g3 -gdwarf-2 -O0 -I"../../OS/ngos/hw/cdb89712" -I"../../OS/ngos" -I"../../OS/ngos/include" -I"../../OS/ngos/rtos/ucosii" -I"./" -I"src/" -I"../../Common/inc" -I"../../OS/uCOS-II/SOURCE" -I"../../OS/ngos/drivers/arm" -I"../../OS/ngos/include/ngos" -I"../../OS/ngip/include" -I"../../OS/ngip/include/ngip" -I"../../Dvcscomponent/Inc" -I"../../Inc" "src/tsk_main.c"
Any idea why the inline function generate theses errors?
Thanks in advance!
I am compiling a kernel module, containing a structure of size 34, using the standard command.
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
The sizeof(some_structure) is coming as 36 instead of 34 i.e. the compiler is padding the structure.
How do I remove this padding?
Running make V=1 shows the gcc compiler options passed as
make -I../inc -C /lib/modules/2.6.29.4-167.fc11.i686.PAE/build M=/home/vishal/20100426_eth_vishal/organised_eth/src modules
make[1]: Entering directory `/usr/src/kernels/2.6.29.4-167.fc11.i686.PAE'
test -e include/linux/autoconf.h -a -e include/config/auto.conf || ( \
echo; \
echo " ERROR: Kernel configuration is invalid."; \
echo " include/linux/autoconf.h or include/config/auto.conf are missing."; \
echo " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo; \
/bin/false)
mkdir -p /home/vishal/20100426_eth_vishal/organised_eth/src/.tmp_versions ; rm -f /home/vishal/20100426_eth_vishal/organised_eth/src/.tmp_versions/*
make -f scripts/Makefile.build obj=/home/vishal/20100426_eth_vishal/organised_eth/src
gcc -Wp,-MD,/home/vishal/20100426_eth_vishal/organised_eth/src/.eth_main.o.d -nostdinc -isystem /usr/lib/gcc/i586-redhat-linux/4.4.0/include -Iinclude -I/usr/src/kernels/2.6.29.4-167.fc11.i686.PAE/arch/x86/include -include include/linux/autoconf.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Os -m32 -msoft-float -mregparm=3 -freg-struct-return -mpreferred-stack-boundary=2 -march=i686 -mtune=generic -Wa,-mtune=generic32 -ffreestanding -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Iarch/x86/include/asm/mach-generic -Iarch/x86/include/asm/mach-default -Wframe-larger-than=1024 -fno-stack-protector -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -pg -Wdeclaration-after-statement -Wno-pointer-sign -fwrapv -fno-dwarf2-cfi-asm -DTX_DESCRIPTOR_IN_SYSTEM_MEMORY -DRX_DESCRIPTOR_IN_SYSTEM_MEMORY -DTX_BUFFER_IN_SYSTEM_MEMORY -DRX_BUFFER_IN_SYSTEM_MEMORY -DALTERNATE_DESCRIPTORS -DEXT_8_BYTE_DESCRIPTOR -O0 -Wall -DT_ETH_1588_051 -DALTERNATE_DESCRIPTORS -DEXT_8_BYTE_DESCRIPTOR -DNETHERNET_INTERRUPTS -DETH_IEEE1588_TESTS -DSNAPTYPSEL_TMSTRENA_TEVENTENA_TESTS -DT_ETH_1588_140_147 -DLOW_DEBUG_PRINTS -DMEDIUM_DEBUG_PRINTS -DHIGH_DEBUG_PRINTS -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(eth_main)" -D"KBUILD_MODNAME=KBUILD_STR(conxt_eth)" -c -o /home/vishal/20100426_eth_vishal/organised_eth/src/eth_main.o /home/vishal/20100426_eth_vishal/organised_eth/src/eth_main.c
If using GCC, you can use the packed attribute on your structure to prevent padding:
struct foo
{
void * bar;
}
__attribute__( ( packed ) );
#pragma pack might work
I suspect that GCC is forcing the total structure to be aligned onto a 32 bit boundary, so its size is a multiple of 4.
Imagine the following.
struct foo
{
void * bar ;
some other stuff .....
};
struct foo my_foo_array[10];
Then if the sizeof(struct foo) is not a multiple of 4 then.
my_foo_array[0].bar has a different memory alignment to my_foo_array[1].bar. The processor would need to perform 2 32 bit memory accesses in order to access all four bytes of my_foo_array[1].bar. x86 processors will do this reassembly of misaligned 32 bit values but most other processors will throw some form of bus error exception which is not good.
The packed attribute signals how the elements of the structure are packed with respect to each other, but in normal operation the start of structure needs to placed on a 32 bit aligned address.
I hope this explains things a little better.