I have a problem with my QTCreator-generated Makefile. Everything is working fine except when I try to create myself a new executable file for my tests, my terminal says: bash: ./RunTests: cannot execute binary file: Exec format error
Here is how my MakeFile rule looks like:
TESTS: ../WannaBeRPG/testes.cpp ../WannaBeRPG/hero.h ../WannaBeRPG/charinterface.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o RunTests ../WannaBeRPG/testes.cpp
Flags are:
CXX = g++
CXXFLAGS = -pipe -g -std=gnu++0x -Wall -W -fPIC $(DEFINES)
INCPATH = -I../WannaBeRPG -I. -I/usr/lib64/qt5/mkspecs/linux-g++
DEFINES = -DQT_QML_DEBUG
If that is anyhow helpful here is my testes.cpp file:
#include <gtest/gtest.h>
#include "hero.h"
TEST(teee, HPTEST)
{
Hero myHero("Hika",150,100,0,0,0,0,0,0,0);
EXPECT_EQ(100,myHero.getHP());
}
int main_tests(int argc, char* argv[])
{
testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}
I am using Fedora.
Any ideas why does this works this way? Primary exec from this Makefile works completely fine.
The -c argument to g++ tells it not to link your binary. Thus, your output file is an object file rather than an executable.
Related
I am trying to compile test.c as described this NanoPi Neo guide. However, when ever I try to run the gcc command to compile, I get this error message...
GNU ld (GNU Binutils for Ubuntu) 2.26.1
Supported emulations:
armelf_linux_eabi
armelfb_linux_eabi
/usr/lib/gcc/arm-linux-gnueabihf/5/../../../arm-linux-gnueabihf/crt1.o: In function `_start':
(.text+0x28): undefined reference to `main'
collect2: error: ld returned 1 exit status
...the command...
sudo gcc -Wall -o test.c -lwiringPi -lpthread -Wl,-V
...and the code I'm trying to compile...
#include <wiringPi.h>
int main(void)
{
wiringPiSetup() ;
pinMode (7, OUTPUT) ;
for(;;)
{
digitalWrite(7, HIGH) ;
delay (500) ;
digitalWrite(7, LOW) ;
delay (500) ;
}
}
May I guess that this is a possible linking issue? I'm just not sure and I really do know how to change it.
I am rather novice-like when it comes to topics like C, Linux and the like. :)
You have not specified any .c source files since the -o specifies the output as #user3386109 mentioned.
sudo gcc -Wall test.c -o output_file_name -lwiringPi -lpthread -Wl,-V
I am using an NVIDIA Jetson TX2. I am trying to generate an ".so" file using "make" for the DynamixelSDK. But I am getting this Error:
mkdir -p ./.objects/
gcc -O2 -O3 -DLINUX -D_GNU_SOURCE -Wall -c -I../../include/dynamixel_sdk -m64 -fPIC -g -c ../../src/dynamixel_sdk/group_bulk_read.c -o .objects/group_bulk_read.o
gcc: error: unrecognized command line option ‘-m64’
Makefile:114: recipe for target '.objects/group_bulk_read.o' failed
make: *** [.objects/group_bulk_read.o] Error 1
You can access the make file at- https://pastebin.com/zz9MNnqp
Here's a part of the MakeFile :
#---------------------------------------------------------------------
# C COMPILER, COMPILER FLAGS, AND TARGET PROGRAM NAME
#---------------------------------------------------------------------
DIR_DXL = ../..
DIR_OBJS = ./.objects
INSTALL_ROOT = /usr/local
MAJ_VERSION = 2
MIN_VERSION = 0
REV_VERSION = 0
TARGET = libdxl_x64_c.so
TARGET1 = $(TARGET).$(MAJ_VERSION)
TARGET2 = $(TARGET).$(MAJ_VERSION).$(MIN_VERSION)
TARGET3 = $(TARGET).$(MAJ_VERSION).$(MIN_VERSION).$(REV_VERSION)
CHK_DIR_EXISTS = test -d
PRINT = echo
STRIP = strip
AR = ar
ARFLAGS = cr
LD = g++
LDFLAGS = -shared -fPIC $(FORMAT)#-Wl,-soname,dxl
LD_CONFIG = ldconfig
CP = cp
CP_ALL = cp -r
RM = rm
RM_ALL = rm -rf
SYMLINK = ln -s
MKDIR = mkdir
CC = gcc
CX = g++
CCFLAGS = -O2 -O3 -DLINUX -D_GNU_SOURCE -Wall -c $(INCLUDES) $(FORMAT) -fPIC -g
CXFLAGS = -O2 -O3 -DLINUX -D_GNU_SOURCE -Wall -c $(INCLUDES) $(FORMAT) -fPIC -g
FORMAT = -m64
INCLUDES += -I$(DIR_DXL)/include/dynamixel_sdk
#---------------------------------------------------------------------
Tried Both the 32 and 64 bit Versions of the MakeFile (for linux).
I don't know hoe to solve this error. Any help would be appreciated.
The makefile assumes that the target is the x86-64 architecture. As a first step, you can simply remove the -m64 option from the FORMAT line in order to get further in the build. However, if the project has never been ported to another architecture, there could well be other target dependencies.
This error usually arises when the march, that is, the architecture of the target machine is not defined correctly. The -m64 line represents that it is being compiled for a 64bit architecture. If you see the Makefile for 32bit, it would be -m32.
Try changing the makefile such that it reads something like :
...
FORMAT = -march=armv8-a+crypto -mcpu=cortex-a57+crypto
....
This is march is usually used for Jetson TX2.
Also, for TX2, GCC options to keep in mind are :
Use latest GCC toolchain 7.2
Use CLANG llvm front end an alternative to GCC
-march=armv8.a+crypto+simd, this enables SIMD, crypto and floating point instruction set and may help.
I am creating an exe and shared library in cygwin.
The library is created and is in the proper place, but when I try to compile the client code daemon, the linking phase says that it can't find the sysutil library.
Error is posted below:
/usr/lib/gcc/i686-pc-cygwin/5.4.0/../../../../i686-pc-cygwin/bin/ld: cannot find -lsysutil
collect2: error: ld returned 1 exit status
make: *** [Makefile:84: daemon] Error 1
I tried exporting the path using LD_LIBRARY_PATH but unfortunately that also didn't help.
daemon.c
#include <stdio.h>
#include <sys_util.h>
int main(){
sys_util();
while(1){
}
return 0;
}
sysutil.c
#include <stdio.h>
#include "sys_util.h"
int sys_util(){
return 0;
}
sysutil.h
int sys_util();
test.bat
g++ -fpic -c sysutil.c
g++ -shared -o libsysutil.so sysutil.o -I.
g++ -c daemon.c -I.
g++ -o daemon.exe daemon.o -L. -lsysutil
del *.o
Shared library is generated sysutil.so in the folder c:/test same as the source code (daemon.c,sysutil.c,sys_util.h,test.bat,libsysutil.so)
Cygwin console output:
/cygdrive/c/test
$ ./test.bat
C:\test>g++ -fpic -c sysutil.c
sysutil.c:1:0: warning: -fpic ignored for target (all code is position independent)
C:\test>g++ -shared -o libsysutil.so sysutil.o -I.
C:\test>g++ -c daemon.c -I.
C:\test>g++ -o daemon.exe daemon.o -L. -lsysutil
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lsysutil
collect2.exe: error: ld returned 1 exit status
C:\test>del *.o
Cygwin expects shared libraries to have the .dll extension.
Change the second line in your batch file to:
g++ -shared -o sysutil.dll sysutil.o -I.
See the users' guide for more info:
https://cygwin.com/cygwin-ug-net/dll.html
I downloaded the zip file from https://github.com/danmar/cppcheck/tree/1.77, unzipped it and gave a make command which generated cppcheck binary.
Next when I run the cppcheck on a test code no error is generated.
sles12-box:/home/test/cppchecker_test/cppcheck-1.77 # cppcheck /home/demo_code/test_code.c
Checking /home/demo_code/test_code.c ...
The source code is
sles12-box:/home/test/cppchecker_test/cppcheck-1.77 # vi /home/demo_code/test_code.c
main(int argc, char* argv[])
{
char cobj[7] = "yahoo";
char *cobjPtr = cobj;
int iobj = 4;
printf("########################### CPPCHECK TEST ############################\n");
yahoo
}
When I tried to compile using the other build command specified in the above mentioned page I get below error
sles12-box:/home/test/cppchecker_test/cppcheck-1.77 # make SRCDIR=build CFGDIR=cfg HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function"
make: pcre-config: Command not found
g++ -Ilib -Iexternals/simplecpp -Iexternals/tinyxml -DCFGDIR=\"cfg\" -O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function -std=c++0x -DHAVE_RULES -DTIXML_USE_STL -c -o build/analyzerinfo.o build/analyzerinfo.cpp
make: pcre-config: Command not found
g++ -Ilib -Iexternals/simplecpp -Iexternals/tinyxml -DCFGDIR=\"cfg\" -O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function -std=c++0x -DHAVE_RULES -DTIXML_USE_STL -c -o build/astutils.o build/astutils.cpp
make: pcre-config: Command not found
g++ -Ilib -Iexternals/simplecpp -Iexternals/tinyxml -DCFGDIR=\"cfg\" -O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function -std=c++0x -DHAVE_RULES -DTIXML_USE_STL -c -o build/check.o build/check.cpp
make: pcre-config: Command not found
.
.
.
I tried building the cppcheck 1.76 version but I get different error there:
sles12-box:/home/test/cppchecker_test/1.76/cppcheck-1.76.1 # sudo make install
Makefile:88: Extraneous text after `else' directive
Makefile:90: Extraneous text after `else' directive
Makefile:90: *** only one `else' per conditional. Stop.
How to get the cppcheck setup ready and functional?
Did you try to install the binary package? https://software.opensuse.org/package/cppcheck
re 1.77: pcre-config is part of the pcre package (most likely the development package
I am trying to build simple XPCOM component for Firefox 3.6.13 under LINUX operating system. I successfully compiled the component using Xulrunner SDK 1.9.2.13. I kept it under components directory. But when I start my firefox firefox console shows error
'Failed to load XPCOM component:
/home/mypc/.mozilla/firefox/cxsm79p6.default/extensions/{1280606b-2510-4fe0-97ef-9b5a22eafe80}/components/MyComponent.so
By referring to this link https://developer.mozilla.org/en/Troubleshooting_XPCOM_components_registration, I followed instructions under title 'Linux-specific hints'. It says to use special linking time option -Wl,-z,defs while linking. So I added these options but now while compiling its showing error as
make: Warning: File `Makefile' has modification time 0.25 s in the future
c++ -Os -Wall -o MyComponent.so
-include xpcom-config.h -DXPCOM_GLUE_USE_NSPR -I /mnt/hgfs/C/Users/sunil/SDKS/LINUX/xulrunner-sdk/include
-I./ -L /mnt/hgfs/C/Users/sunil/SDKS/LINUX/xulrunner-sdk/lib
-lxpcomglue_s -lxpcom -lnspr4 -fno-rtti -fno-exceptions -shared -Wl,-z,defs MyComponent.cpp MyComponentModule.cpp
/tmp/ccMGUTql.o: In function
MyComponent::QueryInterface(nsID
const&, void**)':
MyComponent.cpp:(.text+0x9b):
undefined reference to
NS_TableDrivenQI(void*, QITableEntry
const*, nsID const&, void**)'
/tmp/ccbkZLTz.o: In function
NSGetModule':
MyComponentModule.cpp:(.text+0x15):
undefined reference to
NS_NewGenericModule2(nsModuleInfo
const*, nsIModule*)' collect2: ld
returned 1 exit status make: **
[build] Error 1
My New makefile is as follows
CXX = c++
CPPFLAGS += -fno-rtti \
-fno-exceptions \
-shared \
-Wl,-z,defs
# Change this to point at your Gecko SDK directory.
GECKO_SDK_PATH =/mnt/hgfs/C/Users/sunil/SDKS/LINUX/xulrunner-sdk
# GCC only define which allows us to not have to #include mozilla-config
# in every .cpp file. If your not using GCC remove this line and add
# #include "mozilla-config.h" to each of your .cpp files.
GECKO_CONFIG_INCLUDE = -include xpcom-config.h
GECKO_DEFINES = -DXPCOM_GLUE_USE_NSPR
GECKO_INCLUDES = -I $(GECKO_SDK_PATH)/include
GECKO_LDFLAGS = -L $(GECKO_SDK_PATH)/lib -lxpcomglue_s -lxpcom \
-lnspr4
FILES = MyComponent.cpp MyComponentModule.cpp
TARGET = MyComponent.so
build:
$(CXX) -Os -Wall -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(GECKO_INCLUDES) -I./ $(GECKO_LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(FILES)
chmod +x $(TARGET)
strip $(TARGET)
clean:
rm $(TARGET)
Can somebody help me get around this ?
I think you get this error if your libraries aren't specified correctly. One of these lines might fix it:
GECKO_LDFLAGS = -L$(GECKO_SDK_PATH)/lib -L$(GECKO_SDK_PATH)/bin -Wl,-rpath-link,$(GECKO_SDK_PATH)/bin -lxpcomglue_s -lxpcom -lnspr4
or
$(CXX) -Os -Wall -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(GECKO_INCLUDES) -I./ $(CPPFLAGS) $(CXXFLAGS) $(FILES) $(GECKO_LDFLAGS)