I am trying to create a makefile so I can compile multiple C files. this makefile doesn't work as expected and do only compile ex1 when i run make alland gives error about ex3 (See error log)
CFLAGS=-Wall -g
all:
make ex1
make ex3
clean:
rm -f ex1
rm -f ex3
Error:
make all
make ex1
make[1]: Entering directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
cc -Wall -g ex1.c -o ex1
make[1]: Leaving directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
make ex3
make[1]: Entering directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
make[1]: *** No rule to make target 'ex3'. Stop.
make[1]: Leaving directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 2
it is a bad idea recursively invoke make. You should write your makefile as follows:
CFLAGS=-Wall -g
all: ex1 ex3
clean:
rm -f ex1 ex3
Related
I get a build error when trying to build a flex and lemon project with CMake. Can you help me find what is wrong?
$ make
/usr/bin/cmake -H/home/dac/ClionProjects/openshell -B/home/dac/ClionProjects/openshell --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/dac/ClionProjects/openshell/CMakeFiles /home/dac/ClionProjects/openshell/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/dac/ClionProjects/openshell'
make -f CMakeFiles/lemon.dir/build.make CMakeFiles/lemon.dir/depend
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
cd /home/dac/ClionProjects/openshell && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell/CMakeFiles/lemon.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
make -f CMakeFiles/lemon.dir/build.make CMakeFiles/lemon.dir/build
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
make[2]: Nothing to be done for 'CMakeFiles/lemon.dir/build'.
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
/usr/bin/cmake -E cmake_progress_report /home/dac/ClionProjects/openshell/CMakeFiles 1
[ 16%] Built target lemon
make -f CMakeFiles/openshell.dir/build.make CMakeFiles/openshell.dir/depend
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
cd /home/dac/ClionProjects/openshell && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell/CMakeFiles/openshell.dir/DependInfo.cmake --color=
Scanning dependencies of target openshell
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
make -f CMakeFiles/openshell.dir/build.make CMakeFiles/openshell.dir/build
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
/usr/bin/cmake -E cmake_progress_report /home/dac/ClionProjects/openshell/CMakeFiles 2
[ 33%] Building C object CMakeFiles/openshell.dir/main.c.o
/usr/bin/cc -Wall -Werror -O3 -std=c99 -I/usr/include/readline -o CMakeFiles/openshell.dir/main.c.o -c /home/dac/ClionProjects/openshell/main.c
Linking C executable openshell
/usr/bin/cmake -E cmake_link_script CMakeFiles/openshell.dir/link.txt --verbose=1
/usr/bin/cc -Wall -Werror -O3 -std=c99 CMakeFiles/openshell.dir/main.c.o CMakeFiles/openshell.dir/errors.c.o CMakeFiles/openshell.dir/util.c.o CMakeFiles/openshell.dir/stack.c.o CMakeFiles/openshell.dir/flex/shellparser.c.o -o openshell -rdynamic -lreadline
CMakeFiles/openshell.dir/main.c.o: In function `main':
main.c:(.text.startup+0xef): undefined reference to `yylex_init'
main.c:(.text.startup+0x100): undefined reference to `yyset_in'
main.c:(.text.startup+0x12e): undefined reference to `yylex'
main.c:(.text.startup+0x13a): undefined reference to `yyget_text'
main.c:(.text.startup+0x178): undefined reference to `yylex_destroy'
collect2: error: ld returned 1 exit status
CMakeFiles/openshell.dir/build.make:188: recipe for target 'openshell' failed
make[2]: *** [openshell] Error 1
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
CMakeFiles/Makefile2:98: recipe for target 'CMakeFiles/openshell.dir/all' failed
make[1]: *** [CMakeFiles/openshell.dir/all] Error 2
make[1]: Leaving directory '/home/dac/ClionProjects/openshell'
Makefile:78: recipe for target 'all' failed
make: *** [all] Error 2
My CMake build file is
cmake_minimum_required (VERSION 2.6)
project (openshell)
set(CMAKE_VERBOSE_MAKEFILE on)
include_directories(/usr/include/readline)
#### Lemon bootstrap ####
ADD_EXECUTABLE(lemon lemon.c)
file(GLOB SOURCES "./*.c")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -O3 -std=c99")
add_executable(openshell main.c openshell.h errors.c errors.h util.c util.h stack.c stack.h flex/shellparser.c flex/shellscanner.l flex/shellscanner.h)
target_link_libraries(openshell readline)
You're not linking the Flex library, so you will get linker errors for any Flex functions you use, such as yyset_in.
You can use find_package(FLEX) and after using FLEX_TARGET to define your Flex targets, you can then use something like the following:
# Note: I use "ShellScanner" below as in FLEX_TARGET(ShellScanner flex/shellscanner.l ...)
add_executable(openshell
...
flex/shellparser.c
${FLEX_ShellScanner_OUTPUTS}
)
target_link_libraries(openshell ${READLINE_LIBRARY} ${FLEX_LIBRARIES})
See FindFLEX for more information.
However, I don't see a FindReadline.cmake module with the other modules that CMake provides by default, so you might have to create one yourself or use an existing one such as the one I just linked. There's also the Editline library, which provides similar functionality, and you can use an existing FindEditline.cmake file for that too.
I have made a C program using libusb and I am using following command to compile it:
gcc -o usbtest.o usbtest.c -lusb-1.0
The program is working fine. Next, I added the code of "usbtest.c" to kernel module (usbmod.c) and I am stuck with the make file. I am not sure what command I should pass in the "all" section. Here is what I have made:
obj-m := usbmod.o
KERNEL_DIR = /lib/modules/$(shell uname -r)/build
PWD = $(shell pwd)
all:
$(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order *-
After running make, I am getting the following error:
anubhav#anubhav-Inspiron-3421:~/Desktop/usb$ make
make -C /lib/modules/3.13.0-46-generic/build SUBDIRS=/home/anubhav/Desktop/usb modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-46-generic'
CC [M] /home/anubhav/Desktop/usb/usbmod.o
/home/anubhav/Desktop/usb/usbmod.c:3:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
make[2]: *** [/home/anubhav/Desktop/usb/usbmod.o] Error 1
make[1]: *** [_module_/home/anubhav/Desktop/usb] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-46-generic'
make: *** [all] Error 2
Not sure if need to bring any header file to my working directory or what. Kindly provide suggestions.
Okay, so this link clarifies my doubts to some extent:
[][1]error: stdio.h: No such file or directory error during make
It says "stdio.h" and all do not exist in kernel space and therefore such errors arise. Besides, obviously my module does not contain any printf so I suppose I don't need "stdio.h".
But it does use libusb extensively. So, is there a way to really create this module.
I am trying to learn makefile and below is my modular project structure:
$ pwd
/cygdrive/d/Make/Code
$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
.
|-Build
|-Conversion
|---bin
|-----exe
|-----obj
|---include
|---lib
|---make
|---source
|-Main
|---bin
|-----exe
|-----obj
|---include
|---lib
|---make
|---source
|-Reverse
|---bin
|-----exe
|-----obj
|---include
|---lib
|---make
|---source
Three modules are 1)Conversion 2)Reverse 3)Main. makefile for each these modules are placed in respective make folder and they prepare corresponding .o files correctly and place them in bin/obj of respective folders.
Build directory is for generating the .exe file as shown below:
$ cat makefile
all:
cd ../Conversion/make; make
cd ../Reverse/make; make
cd ../Main/make; make
Conversion:
cd ../Conversion/make; make
Reverse:
cd ../Reverse/make; make
Main:
cd ../Main/make; make
exeApp:
cd ../Main/make; make App
cConversion:
cd ../Conversion/make; make clean
cReverse:
cd ../Reverse/make; make clean
cMain:
cd ../Main/make ; make clean
cleanAll:
cd ../Conversion/make; make clean
cd ../Reverse/make; make clean
cd ../Main/make; make clean
and the makefile for main is:
#VPATH= ./../source
INCLUDES= ./../include
OBJDIR= ./../bin/obj
EXEDIR= ./../bin/exe
OBJLOOKDIR= ./../../Conversion/bin/obj:./../../Reverse/bin/obj:./../../Main/bin/obj
#CONBIN= ./../../Conversion/bin/obj
#REVBIN= ./../../Reverse/bin/obj
#MAINBIN= ./../../Main/bin/obj
vpath %.h $(INCLUDES)
vpath %.o $(OBJLOOKDIR)
vpath %.c ./../source
CC= gcc
CFLAGS= -Wall -c -I$(INCLUDES)
OBJECTS= driver.o
PROJECTOBJECTS= binary.o hex.o octal.o reverseNum.o driver.o
main: $(OBJECTS)
driver.o: driver.c conversion.h
$(CC) $(CFLAGS) $< -o $(OBJDIR)/$#
App: $(PROJECTOBJECTS)
$(CC) -Wall $< -o $(EXEDIR)/$#
clean:
rm -rf $(OBJDIR)/*.o *~ $(EXEDIR)/*
But when I run make exeApp, I get below error:
$ make exeApp
cd ../Main/make; make App
make[1]: Entering directory '/cygdrive/d/Make/Code/Main/make'
gcc -Wall ./../../Conversion/bin/obj/binary.o -o ./../bin/exe/App
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-1.7.28-2/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain#16'
collect2: error: ld returned 1 exit status
makefile:26: recipe for target 'App' failed
make[1]: *** [App] Error 1
make[1]: Leaving directory '/cygdrive/d/Make/Code/Main/make'
makefile:17: recipe for target 'exeApp' failed
make: *** [exeApp] Error 2
Some how it is not being translated to below rule:
$ pwd
/cygdrive/d/Make/Code/Main/make
Gaurav#Gaurav-PC /cygdrive/d/Make/Code/Main/make
$ gcc -Wall ./../../Conversion/bin/obj/binary.o ./../../Conversion/bin/obj/hex.o ./../../Conversion/bin/obj/octal.o ./../../Reverse/bin/obj/reverseNum.o ./../../Main/bin/obj/driver.o -o Trial
Gaurav#Gaurav-PC /cygdrive/d/Make/Code/Main/make
$ ls
makefile makefileold Trial.exe
as The above rule compiles file, but exeApp rule translated only to gcc -Wall ./../../Conversion/bin/obj/binary.o -o ./../bin/exe/App . It should have been to gcc -Wall ./../../Conversion/bin/obj/binary.o ./../../Conversion/bin/obj/hex.o ./../../Conversion/bin/obj/octal.o ./../../Reverse/bin/obj/reverseNum.o ./../../Main/bin/obj/driver.o -o ./../bin/exe/App
I am not able to figure out why?
Can anyone help, Please.
Thanks
I'm trying to use libical for a C-project. Unfortunately, the make command gives me the following output:
/Applications/Xcode.app/Contents/Developer/usr/bin/make all-recursive
Making all in design-data
make[2]: Nothing to be done for `all'.
Making all in doc
make[2]: Nothing to be done for `all'.
Making all in scripts
make[2]: Nothing to be done for `all'.
Making all in test-data
make[2]: Nothing to be done for `all'.
Making all in src
Making all in libical
/Applications/Xcode.app/Contents/Developer/usr/bin/make all-am
/bin/sh ../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../src -I../../src -I../../src/libical -I../../src/libical -I. -DPACKAGE_DATA_DIR=\""/usr/local/libical/share/libical"\" -g -O2 -MT icalderivedparameter.lo -MD -MP -MF .deps/icalderivedparameter.Tpo -c -o icalderivedparameter.lo icalderivedparameter.c
mv -f .deps/icalderivedparameter.Tpo .deps/icalderivedparameter.Plo
mv: rename .deps/icalderivedparameter.Tpo to .deps/icalderivedparameter.Plo: No such file or directory
make[4]: *** [icalderivedparameter.lo] Error 1
make[3]: *** [all] Error 2
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
I'm not sure whats wrong here. I'm running OS X 10.9 and gcc.
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
You must call ./bootstrap.
./bootstrap
./configure
make
make install
Bootstrap was the key for me.
My problem is the following one:
When installing Axis2/c under the guidance of http://petio.org/ws/web_services_page7.html , which seems to be an adjusted manual from the official site I have a problem right after executing the make command in terminal.
At exactly this point:
$ cd /tmp/axis/axis2c-src-1.6.0
$ ./configure --prefix=${AXIS2C_HOME} --enable-libxml2=yes
$ make
I get this error:
XXX#XXXPC:~/Tools/axis2c/axis2c-src-1.5.0$ make
make all-recursive
make[1]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0'
Making all in util
make[2]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
make all-recursive
make[3]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
Making all in src
make[4]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src'
Making all in platforms/unix
make[5]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src/platforms/unix'
/bin/bash ../../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../include -I../../../include/platforms -I../../../include/platforms/unix -g -O2 -D_LARGEFILE64_SOURCE -ansi -Wall -Werror -Wno-implicit-function-declaration -D_GNU_SOURCE -MT uuid_gen_unix.lo -MD -MP -MF .deps/uuid_gen_unix.Tpo -c -o uuid_gen_unix.lo uuid_gen_unix.c
gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../include -I../../../include/platforms -I../../../include/platforms/unix -g -O2 -D_LARGEFILE64_SOURCE -ansi -Wall -Werror -Wno-implicit-function-declaration -D_GNU_SOURCE -MT uuid_gen_unix.lo -MD -MP -MF .deps/uuid_gen_unix.Tpo -c uuid_gen_unix.c -fPIC -DPIC -o .libs/uuid_gen_unix.o
**uuid_gen_unix.c: In function ‘axutil_uuid_gen_v1’:
uuid_gen_unix.c:62:20: error: variable ‘tv’ set but not used [-Werror=unused-but-set-variable]**
cc1: all warnings being treated as errors
make[5]: *** [uuid_gen_unix.lo] Error 1
make[5]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src/platforms/unix'
make[4]: *** [all-recursive] Error 1
make[4]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0'
make: *** [all] Error 2
I am not able to understand the reason why this error is being produced.
Because 1.6.0 version is down, I am using the 1.5.0 source version of axis2/c from the official site : http://axis.apache.org/axis2/c/core/download.cgi .
I have additionally installed Apache2 and libxml2, OpenSSL, cURL, libiconv, and zlib.
libraries.
I need your help because I am trying to build a serious project.
Thanks in advance.
Link to mirror of original Axis2/C-1.6.0 source distribution is here.
The main problem is with -Werror flag.
To compile original Axis2/C with modern compiler you must remove -Werror string from build scripts. To do that run this command after unpacking tarball:
find -type f -name configure -exec sed -i '/CFLAGS/s/-Werror//g' {} \;
Then configure and make Axis2/C.
Note: Original Axis2/C-1.6.0 has many issues like memory leaks and crashes. Consider using Axis2/C unofficial project instead. Most critical Axis2/C-1.6.0's issues is fixed within that project.
Also it have additional features https://code.google.com/p/axis2c-unofficial/wiki/IssuesList like JSON support and enhanced CURL-based transport authentication (and some other features).
There is an manual on how to install Axis2/C unofficial on Linux.