SQlite seems to use an own varian of libtool. Now I have added an extension to SQLite depends on some C++ code. However, I'm not able to link the C and C++ code. The error I get is:
c++ -Wl,-undefined,error -o libsqlite3.la sqlite3.lo -lz extsql.lo \
-rpath "/usr/local/lib"
ld: warning: ignoring file sqlite3.lo, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x23 0x20 0x73 0x71 0x6C 0x69 0x74 0x65 0x33 0x2E 0x6C 0x6F 0x20 0x2D 0x20 0x61 )
ld: warning: ignoring file extsql.lo, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x23 0x20 0x65 0x64 0x67 0x65 0x73 0x71 0x6C 0x2E 0x6C 0x6F 0x20 0x2D 0x20 0x61 )
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Thesee are my changes to the Makefile.in:
LTCOMPILECXX = $(LIBTOOL) --mode=compile --tag=CXX $(TCC) $(LTCOMPILE_EXTRAS)
LTLINKCXX = $(LIBTOOL) --tag=CXX --mode=link $(TCXX) $(LTCOMPILE_EXTRAS) #LDFLAGS# $(LTLINK_EXTRAS)
libsqlite3.la: $(LIBOBJ)
$(CXX) -Wl,-undefined,error -o $# $(LIBOBJ) $(TLIBS) \
${ALLOWRELEASE} -rpath "$(libdir)"
libtclsqlite3.la: tclsqlite.lo libsqlite3.la
$(CXX) -Wl,-undefined,error -o $# tclsqlite.lo \
libsqlite3.la #TCL_STUB_LIB_SPEC# $(TLIBS) \
-rpath "$(TCLLIBDIR)" \
-avoid-version
extsql$(TEXE): shell.c libsqlite3.la
$(CXX) $(READLINE_FLAGS) $(SHELL_OPT) -o $# \
shell.c libsqlite3.la \
$(LIBREADLINE) $(TLIBS) -rpath "$(libdir)"
extsql.lo: $(TOP)/extsql/extsql extsql_ext.h
$(LTCOMPILECXX) -c $(TOP)/extsql/extsql.cpp
Note the use of CXX instead of the original LTLINK command for the original makefile:
libsqlite3.la: $(LIBOBJ)
$(LTLINK) -no-undefined -o $# $(LIBOBJ) $(TLIBS) \
${ALLOWRELEASE} -rpath "$(libdir)" -version-info "8:6:8"
libtclsqlite3.la: tclsqlite.lo libsqlite3.la
$(LTLINK) -no-undefined -o $# tclsqlite.lo \
libsqlite3.la #TCL_STUB_LIB_SPEC# $(TLIBS) \
-rpath "$(TCLLIBDIR)" \
-version-info "8:6:8" \
-avoid-version
sqlite3$(TEXE): shell.c sqlite3.c
$(LTLINK) $(READLINE_FLAGS) $(SHELL_OPT) -o $# \
shell.c sqlite3.c \
$(LIBREADLINE) $(TLIBS) -rpath "$(libdir)"
The original makefile can be found here:
https://github.com/sqlite/sqlite/blob/branch-3.39/Makefile.in
Related
We were using grpc 1.15.0 for long time and linked to application compiled with C++11.
We try to upgrade grpc to 1.46.5 (base on documentation gRPC C++ 1.46 will be the last release supporting C++11)
I had simple test program that only calls
std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel("https://127.0.0.1:9999", ssl_creds);
With 1.15.0 it was compiled without any errors
g++ adam_test1.cpp -std=c++11 -I/home/adam/grpc1.15.0/obj/linux_x86-64/3rd/include -L/home/adam/grpc1.15.0/obj/linux_x86-64/3rd/lib64 -l:libgrpc++.a -l:libgrpc.a -l:libgpr.a -l:libaddress_sorting.a -lcrypto -lssl -lcares -lz -pthread -o adam_test1
The same with 1.46.5 show many undefined reference.
Tried even add some libabsl but still failing
g++ adam_test1.cpp -std=c++11 -I/home/adam/grpc1.46.5/obj/linux_x86-64/3rd/include -L/usr/lib64 -L/home/adam/grpc1.46.6/obj/linux_x86-64/3rd/lib64 -l:libgrpc++.a -l:libgrpc.a -l:libgpr.a -l:libaddress_sorting.a -l:libabsl_base.a -l:libabsl_cord.a -l:libabsl_status.a -l:libabsl_strings.a -l:libabsl_synchronization.a -lcrypto -lssl -lcares -lz -pthread -lstdc++ -o adam_test2
some logs
/home/adam/grpc1.46.5/obj/linux_x86-64/3rd/lib64/libgrpc.a(client_channel.cc.o): In function `grpc_core::ClientChannel::CreateOrUpdateLbPolicyLocked(grpc_core::RefCountedPtr<grpc_core::LoadBalancingPolicy::Config>, absl::lts_20211102::optional<std::string> const&, grpc_core::Resolver::Result)':
client_channel.cc:(.text+0x8c01): undefined reference to `absl::lts_20211102::internal_statusor::Helper::HandleInvalidStatusCtorArg(absl::lts_20211102::Status*)'
/home/adam/grpc1.46.5/obj/linux_x86-64/3rd/lib64/libgrpc.a(client_channel.cc.o): In function `std::_Function_handler<void (), grpc_core::ClientChannel::SubchannelWrapper::WatcherWrapper::OnConnectivityStateChange()::{lambda()#1}>::_M_invoke(std::_Any_data const&)':
client_channel.cc:(.text._ZNSt17_Function_handlerIFvvEZN9grpc_core13ClientChannel17SubchannelWrapper14WatcherWrapper25OnConnectivityStateChangeEvEUlvE_E9_M_invokeERKSt9_Any_data[_ZNSt17_Function_handlerIFvvEZN9grpc_core13ClientChannel17SubchannelWrapper14WatcherWrapper25OnConnectivityStateChangeEvEUlvE_E9_M_invokeERKSt9_Any_data]+0x4ce): undefined reference to `absl::lts_20211102::optional_internal::throw_bad_optional_access()'
/home/adam/grpc1.46.5/obj/linux_x86-64/3rd/lib64/libgrpc.a(client_channel.cc.o): In function `absl::lts_20211102::StatusOr<absl::lts_20211102::InlinedVector<grpc_core::ServerAddress, 1ul, std::allocator<grpc_core::ServerAddress> > >::StatusOr()':
client_channel.cc:(.text._ZN4absl12lts_202111028StatusOrINS0_13InlinedVectorIN9grpc_core13ServerAddressELm1ESaIS4_EEEEC2Ev[_ZN4absl12lts_202111028StatusOrINS0_13InlinedVectorIN9grpc_core13ServerAddressELm1ESaIS4_EEEEC5Ev]+0x44): undefined reference to `absl::lts_20211102::internal_statusor::Helper::HandleInvalidStatusCtorArg(absl::lts_20211102::Status*)'
/home/adam/grpc1.46.5/obj/linux_x86-64/3rd/lib64/libgrpc.a(lb_policy.cc.o): In function `grpc_core::LoadBalancingPolicy::UpdateArgs::operator=(grpc_core::LoadBalancingPolicy::UpdateArgs&&)':
lb_policy.cc:(.text+0x69e): undefined reference to `absl::lts_20211102::internal_statusor::Helper::HandleInvalidStatusCtorArg(absl::lts_20211102::Status*)'
/home/adam/grpc1.46.5/obj/linux_x86-64/3rd/lib64/libgrpc.a(lb_policy.cc.o): In function `grpc_core::LoadBalancingPolicy::UpdateArgs::operator=(grpc_core::LoadBalancingPolicy::UpdateArgs const&)':
lb_policy.cc:(.text+0x9ac): undefined reference to `absl::lts_20211102::internal_statusor::Helper::HandleInvalidStatusCtorArg(absl::lts_20211102::Status*)'
/home/adam/grpc1.46.5/obj/linux_x86-64/3rd/lib64/libgrpc.a(lb_policy_registry.cc.o): In function `grpc_core::LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(grpc_core::Json const&, grpc_error**)':
The grpc and absl are also compiled with -std=c++11. What should be the correct cmake command to build libgrpc.a with C++11 and what other abls libs need to be linked when using it ?
git submodule update --init ${GRPC_SOURCE}/third_party/re2/ ${GRPC_SOURCE}/third_party/abseil-cpp/
# Install absl
mkdir -p "third_party/abseil-cpp/cmake/build"
pushd "third_party/abseil-cpp/cmake/build"
cmake -std=c++11 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${PROD_DIR} -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ../..
make -j4 install
popd
cmake \
-std=c++11 \
-DPKG_CONFIG_USE_CMAKE_PREFIX_PATH=1 \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DgRPC_CARES_PROVIDER=package \
-DgRPC_ABSL_PROVIDER=package \
-DgRPC_PROTOBUF_PROVIDER=package \
-DgRPC_RE2_PROVIDER=package \
-DgRPC_SSL_PROVIDER=package \
-DgRPC_ZLIB_PROVIDER=package \
-DgRPC_ABSL_PROVIDER=module \
-DgRPC_INSTALL_SUPPORTED_FROM_MODULE=ON \
-Dc-ares_DIR=${CARES_DIR}/lib/cmake/c-ares \
-DgRPC_INSTALL_LIBDIR=${SYS_LIB_DIR} \
-D_gRPC_PROTOBUF_PROTOC=${PROTO_DIR} \
-DCMAKE_PREFIX_PATH=${OPENSSL_DIR}\\;${PROTO_DIR}\\;${ZLIB_DIR} \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-R/opt/3rd/lib64 -lprotoc -lprotobuf" \
-DCMAKE_INSTALL_PREFIX=${PROD_DIR} \
-DCMAKE_CXX_FLAGS="-I${PROTO_DIR}/include -I${OPENSSL_DIR}/include -I./third_party/cares -L${PROTO_DIR}/lib -L${OPENSSL_DIR}/lib" \
-DCMAKE_C_FLAGS="-I${PROTO_DIR}/include -I${OPENSSL_DIR}/include -L${PROTO_DIR}/lib -L${OPENSSL_DIR}/lib" \
-LAH \
../..
make && make install
I was able to build after adding libabsl in correct order and also need to run on server with newer libstdc++.so that knows __cxa_throw_bad_array_length
g++ adam_test1.cpp -std=c++11 -I/home/adam/obj/linux_x86-64/3rd/include -L/usr/lib64 -L/home/adam/obj/linux_x86-64/3rd/lib64 -l:libgrpc++.a -l:libgrpc.a -l:libgpr.a -l:libaddress_sorting.a -l:libabsl_cord.a -l:libabsl_status.a -l:libabsl_strings.a -l:libabsl_synchronization.a -l:libabsl_statusor.a -l:libabsl_bad_optional_access.a -l:libabsl_bad_variant_access.a -l:libabsl_time.a -l:libabsl_time_zone.a -l:libabsl_throw_delegate.a -l:libabsl_hash.a -l:libabsl_raw_logging_internal.a -l:libabsl_log_severity.a -l:libabsl_strings_internal.a -l:libabsl_malloc_internal.a -l:libre2.a -l:libupb.a -l:libabsl_base.a -l:libabsl_spinlock_wait.a -l:libabsl_symbolize.a -l:libabsl_str_format_internal.a -l:libabsl_random_internal_randen.a -l:libabsl_random_internal_randen_hwaes.a -l:libabsl_random_internal_randen_hwaes_impl.a -l:libabsl_random_internal_randen_slow.a -l:libabsl_random_internal_pool_urbg.a -l:libabsl_random_internal_platform.a -l:libabsl_random_internal_seed_material.a -l:libabsl_random_seed_gen_exception.a -l:libabsl_cord.a -l:libabsl_cord_internal.a -l:libabsl_cordz_functions.a -l:libabsl_cordz_info.a -l:libabsl_int128.a -l:libabsl_demangle_internal.a -l:libabsl_stacktrace.a -l:libabsl_debugging_internal.a -l:libabsl_cordz_handle.a -l:libabsl_city.a -l:libabsl_low_level_hash.a -l:libabsl_exponential_biased.a -lcrypto -lssl -lcares -lz -pthread -lstdc++ -o adam_test2
bash-4.4# nm -D /usr/lib64/libstdc++.so.6.0.25 | grep throw_bad
00000000000c02c0 T _ZSt16__throw_bad_castv
00000000000c0280 T _ZSt17__throw_bad_allocv
00000000000c0300 T _ZSt18__throw_bad_typeidv
00000000000c0240 T _ZSt21__throw_bad_exceptionv
00000000000c0720 T _ZSt25__throw_bad_function_callv
00000000000949e0 T __cxa_throw_bad_array_length
00000000000954e0 T __cxa_throw_bad_array_new_length
I've got some Errors while running the Makefile. I am currently using MacOS Mojave, and got some weird errors and I am not able to understand them. The Makefile hadn't work at all, there was an error in ASPARAMS = -m32 (before that it was ASPARAMS= --32 {didn't work}. Now the Makefile has no errors but a other file does. Here is the code of the Makefile:
GPPPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore
ASPARAMS = -m32
LDPARAMS = -melf_i386
objects = loader.o kernel.o
%.o: %.cpp
g++ $(GPPPARAMS) -o $# -c $<
%.o: %.s
as $(ASPARAMS) -o $# $<
mykernel.bin: linker.ld $(objects)
ld $(LDPARAMS) -T $< -o $# $(objects)
install: mykernel.bin
sudo cp $< /boot/mykernel.bin
mykernel.iso: mykernel.bin
mkdir iso
mkdir iso/boot
mkdir iso/boot/grub
cp $< iso/boot/
echo 'set timeout-0' >> iso/boot/grub/grub.cfg
echo 'set default-0' >> iso/boot/grub/grub.cfg
echo 'menuentry "My Operating System"{' >> iso/boot/grub/grub.cfg
echo ' multiboot /boot/mykernel.bin' >> iso/boot/grub/grub.cfg
echo ' boot' >> iso/boot/grub/grub.cfg
echo '}' >> iso/boot/grub/grub.cfg
grub-mkrescue --output=$# iso
rm -rf iso
run: mykernel.iso
(killall VirtualBox && sleep 1) || true
VirtualBox --startvm "My Operating System" &
Here are the errors:
loader.s:5:20: error: unexpected token in '.section' directive
.section .multiboot
^
loader.s:12:15: error: unexpected token in '.section' directive
.section .text
^
loader.s:29:15: error: unexpected token in '.section' directive
.section .bss
^
make: *** [loader.o] Error 1
And here is the file were the errors appear:
.set MAGIC, 0x1badb002
.set FLAGS, (1<<0 | 1<<1)
.set CHECKSUM, -(MAGIC + FLAGS)
.section .multiboot
.long MAGIC
.long FLAGS
.long CHECKSUM
.section .text
.extern kernelMain
.extern callConstructors
.global loader
loader:
mov $kernel_stack, %esp
call callConstructors
push %eax
push %ebx
call kernelMain
_stop:
cli
hlt
jmp _stop
.section .bss
.space 2*1024*1024;
kernel_stack:
I've been writing C for 2-3 years and recently picked up assembly but as I use Windows I've never needed to use make files before as I've just used Visual Studio. I'm trying to use Cygwin and an i686 cross compiler to compile c and assembly files, and then link them together into a binary file representing my operating system. I am new to make files so I don't know how to do this properly. This is what I've got so far for the Makefile:
CC = i686-elf-gcc
CC_FLAGS = -c -std=gnu99 -ffreestanding -O2 -Wall -Wextra -I./include
AS = i686-elf-as
LD = i686-elf-gcc -T linker.ld -o myos.bin
LD_FLAGS = -ffreestanding -O2 -nostdlib -lgcc
O_FILES = $(wildcard src/*.o)
all: $(O_FILES)
$(LD) $(LD_FLAGS) $(O_FILES)
src/%.o: src/%.c
$(CC) $(CC_FLAGS) -o $# $<
src/%.o: src/%.asm
$(AS) -o $# $<
I'm getting an error stating that the linker can't find the entry symbol _start so obviously nothing is compiling. How would I fix this?
My src/linker.ld file that defines _start as the entry point is:
ENTRY(_start)
SECTIONS
{
. = 1M;
.text BLOCK(4K) : ALIGN(4K)
{
*(.multiboot)
*(.text)
}
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata)
}
.data BLOCK(4K) : ALIGN(4K)
{
*(.data)
}
.bss BLOCK(4K) : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
}
The src/boot.asmfile I'm using that defines my _start label is:
# Declare constants for the multiboot header.
.set ALIGN, 1<<0 # align loaded modules on page boundaries
.set MEMINFO, 1<<1 # provide memory map
.set FLAGS, ALIGN | MEMINFO # this is the Multiboot 'flag' field
.set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header
.set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot
.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
.section .bss
.align 16
stack_bottom:
.skip 16384 # 16 KiB
stack_top:
.section .text
.global _start
.type _start, #function
_start:
mov $stack_top, %esp
call kernel_main
cli
1: hlt
jmp 1b
.size _start, . - _start
You will need to modify your Makefile to something like this:
CC = i686-elf-gcc
AS = i686-elf-as
LD = i686-elf-gcc
AS_FLAGS =
LD_FLAGS = -ffreestanding -nostdlib -lgcc -Tlinker.ld
CC_FLAGS = -c -std=gnu99 -ffreestanding -O2 -Wall -Wextra -I./include
C_FILES := $(wildcard src/*.c)
ASM_FILES := $(wildcard src/*.asm)
O_FILES := $(C_FILES:.c=.o) $(ASM_FILES:.asm=.o)
KERNEL_BIN := myos.bin
all: $(KERNEL_BIN)
clean:
rm -f $(KERNEL_BIN) $(O_FILES)
$(KERNEL_BIN): $(O_FILES)
$(LD) $(LD_FLAGS) -o $# $^
%.o: %.c
$(CC) $(CC_FLAGS) -o $# $<
%.o: %.asm
$(AS) $(AS_FLAGS) -o $# $<
This Makefile is different in that we construct a list of ASM files and C files. I also cleaned up the LD_FLAGS a bit and added an extra rule to create myos.bin and to clean the object and bin files.
In your current code you'd have the Makefile variables with this in them after expansion:
C_FILES = src/string.c src/tty.c src/kernel.c
ASM_FILES = src/boot.asm
O_FILES = src/string.o src/tty.o src/kernel.o src/boot.o
O_FILES was derived from concatenating both file lists together and replacing the .c and .asm extensions with .o. This is the list of all the objects that need to be generated from their source files.
With GNU Assembler it is customary to use files with .s extensions (or .S if you want to use the C preprocessor) rather than .asm
The reason the _start label wasn't found is because the assembly files were not being processed. This means that boot.asm was not becoming boot.o and thus wasn't being linked at all.
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.
I found a bare-metal example for a board different from mine so I will have to modify the loader script but for now I just want to be able to compile and link the example as it is.
I copied the arm-none-eabi cross-compiler to the directory just above c_blinky which is where the source files are.
(I have a diagram of the directory structure on a page on my website)
Here's the makefile:
ifeq ($(GNU_ARM),)
GNU_ARM = ../arm-none-eabi/bin
endif
CC := $(GNU_ARM)/arm-none-eabi-gcc
CPP := $(GNU_ARM)/arm-none-eabi-g++
ASM := $(GNU_ARM)/arm-none-eabi-as
LINK := $(GNU_ARM)/arm-none-eabi-gcc
BIN := $(GNU_ARM)/arm-none-eabi-objcopy
RM := rm -rf
MKDIR := mkdir
BLDDIR = .
CCINC = -I$(BLDDIR)
APP_DEP = $(BLDDIR)/bsp.h \
$(BLDDIR)/arm_exc.h \
$(BLDDIR)/isr.h
APP_NAME = blinky
ARM_CORE = arm7tdmi
ifeq (rel, $(CONF)) # Release configuration
BINDIR = rel
CCFLAGS = -c -mcpu=$(ARM_CORE) -mthumb-interwork -Os \
-mlong-calls -ffunction-sections -Wall -DNDBEBUG -o$#
ASMFLAGS = -mcpu=$(ARM_CORE) -mthumb-interwork -o$#
LINKFLAGS = -T .\$(APP_NAME).ld -o $(BINDIR)\$(APP_NAME).elf \
-Wl,-Map,$(BINDIR)\$(APP_NAME).map,--cref,--gc-sections
else # default Debug configuration
BINDIR = dbg
CCFLAGS = -g -c -mcpu=$(ARM_CORE) -mthumb-interwork -O \
-mlong-calls -ffunction-sections -Wall -o$#
ASMFLAGS = -g -mcpu=$(ARM_CORE) -mthumb-interwork -o$#
LINKFLAGS = -T .\$(APP_NAME).ld -o $(BINDIR)\$(APP_NAME).elf \
-Wl,-Map,$(BINDIR)\$(APP_NAME).map,--cref,--gc-sections
endif
all: $(BINDIR)/$(APP_NAME).bin
$(BINDIR)/$(APP_NAME).bin : $(BINDIR)/$(APP_NAME).elf
$(BIN) -O binary $(BINDIR)/$(APP_NAME).elf $(BINDIR)/$(APP_NAME).bin
$(BINDIR)/$(APP_NAME).elf : \
./$(APP_NAME).ld \
$(BINDIR)/startup.o \
$(BINDIR)/arm_exc.o \
$(BINDIR)/low_level_init.o \
$(BINDIR)/isr.o \
$(BINDIR)/bsp.o \
$(BINDIR)/blinky.o
$(LINK) \
$(BINDIR)/startup.o \
$(BINDIR)/arm_exc.o \
$(BINDIR)/low_level_init.o \
$(BINDIR)/isr.o \
$(BINDIR)/bsp.o \
$(BINDIR)/blinky.o \
$(LINKFLAGS)
$(BINDIR)/startup.o: $(BLDDIR)/startup.s
$(ASM) $(ASMFLAGS) $<
$(BINDIR)/arm_exc.o: $(BLDDIR)/arm_exc.s
$(ASM) $(ASMFLAGS) $<
# choose the ARM or THUMB compilation for each module...
$(BINDIR)/low_level_init.o: $(BLDDIR)/low_level_init.c $(APP_DEP)
$(CC) -marm $(CCFLAGS) $(CCINC) $<
$(BINDIR)/isr.o: $(BLDDIR)/isr.c $(APP_DEP)
$(CC) -marm $(CCFLAGS) $(CCINC) $<
$(BINDIR)/bsp.o: $(BLDDIR)/bsp.c $(APP_DEP)
$(CC) -mthumb $(CCFLAGS) $(CCINC) $<
$(BINDIR)/blinky.o: $(BLDDIR)/blinky.c $(APP_DEP)
$(CC) -mthumb $(CCFLAGS) $(CCINC) $<
I set GNU_ARM in the makefile to ../arm-none-eabi/bin and ran make and got the following error:
(the file blinky.ld does exist in the source directory)
../arm-none-eabi/bin/arm-none-eabi-gcc \
dbg/startup.o \
dbg/arm_exc.o \
dbg/low_level_init.o \
dbg/isr.o \
dbg/bsp.o \
dbg/blinky.o \
-T .\blinky.ld -o dbg\blinky.elf -Wl,-Map,dbg\blinky.map,--cref,--gc-sections
/home/dan/dev/compile/bare-metal/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: cannot open linker script file .blinky.ld: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [dbg/blinky.elf] Error 1
I thought the LINK assignment at the beginning should be:
LINK := $(GNU_ARM)/arm-none-eabi-ld
and not
LINK := $(GNU_ARM)/arm-none-eabi-gcc
and I got:
../arm-none-eabi/bin/arm-none-eabi-ld \
dbg/startup.o \
dbg/arm_exc.o \
dbg/low_level_init.o \
dbg/isr.o \
dbg/bsp.o \
dbg/blinky.o \
-T .\blinky.ld -o dbg\blinky.elf -Wl,-Map,dbg\blinky.map,--cref,--gc-sections
../arm-none-eabi/bin/arm-none-eabi-ld: cannot open linker script file .blinky.ld: No such file or directory
make: *** [dbg/blinky.elf] Error 1
It looks like arm-none-eabi-gcc is calling collect2 in lib/gcc/arm-none-eabi/4.9.3 which in turn calls ld which is not in the main bin directory:
/home/dan/dev/compile/bare-metal/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:
I tried making a symbolic link to arm-none-eabi-ld as ld and got the same error.