I am new to programming. Additionally, I am super confused about compiling, debugging, executing, running. What does each of them mean and what starts first?
Thanks.
without make it complicated
compile: make your code executable, creating a file that can be executed
debug: is the action of check your code for execution instruction by instruction
execute/run: make your code produce the result that you coded for
C basic example
requisite
gcc (compiler)
shell (ex: bash)
terminal emulator
getting started
the main folder:
PROJECT
│
├─ README.md
│
└─ main.c
main.c: this file contain the code
#include<stdio.h>
int main(void)
{
char ch = 'd';
printf("hello worl%c",ch);
return 0;
}
README.md: contain the explanation of the project
Compile
open the terminal in this folder and enter:
gcc -o build/out main.c
gcc: the compiler executable
-o build/out: the name of the output
main.c: the name of the file to compile
than this is what we should see
PROJECT
│
├─ README.md
│
├─ build
│ └─ out
│
└─ main.c
<!-- build is just the name of the
folder were the executable is placed -->
Execute/Run
open the terminal in this folder and enter:
./build/out
# result:
# > ./a.out
# hello world
Related
Let's say I've got the following project structure:
<ASM_Project>/
├── <src>/
│ └── <boot>/
│ ├── boot.s
│ └── functions.s
└── Makefile
boot.s:
_start:
jmp testing
.include "src/boot/functions.s"
testing:
Makefile:
src/boot/boot.o: src/boot/boot.s src/boot/functions.s
as -o $# $<
boot.s and functions.s are in the same folder and yet .include "functions" doesn't seem to work in this case:
Ernie#Sanderson:~/ASM_Project$ make
as -o src/boot/boot.o src/boot/boot.s
src/boot/boot.s: Assembler messages:
src/boot/boot.s:11: Error: can't open functions.s for reading: No such file or directory
make: *** [Makefile:23: src/boot/boot.o] Error 1
Is there a way to pull it off though?
When I try to link librubberband.a I get:
libavfilter/af_rubberband.c:236: error: undefined reference to 'rubberband_set_pitch_scale'
I compiled rubberband for armv7a, and created a static library (rubberband.a).
I checked the library, and It contained the needed symbols (using nm).
I verified that librubberband.a is in the libpath (-L)
I verified that extern C exists in the rubberband.c.h file.
Any ideas?
The error happened in the link stage. Make sure the link directory has been added to -L parameters of your compiler.
-L/directory/of/your/lib
And specify the library with -l option.
So make sure the option -L/directory/of/your/lib -lrubberband set for your compiler when you build ffmpeg with rubberband support.
If you didn't use pkg-config to add the library. You can use the option --extra-ldflags to add when configure ffmpeg before build.
./configure \
# some configure options
--extra-ldflags="-L/directory/of/your/lib -lrubberband" \
# more configure options
If you use pkg-config to find out the libraries. Just add the library.pc directory to PKG_CONFIG_PATH, and let the build system do the remaining.
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/directory/to/your/rubberband.pc
Updated
Finally make sure you link against to the same architecture of your library.
$ arm-linux-androideabi-readelf -h librubberband.a |grep 'Class\|Machine
For armeabi-v7a, it should be ELF32 and ARM.
Updated
I have cloned the source of rubberband from https://bitbucket.org/breakfastquay/rubberband
And found the function call rubberband_set_pitch_scale is defined at src/rubberband-c.cpp, this file is not include in Android.mk when build for Android (WHY?).
So you have to add this file to build.
RUBBERBAND_SRC_FILES = ... \
$(RUBBERBAND_SRC_PATH)/rubberband-c.cpp
After build done, you need to create directory structure like below
.
├── include
│ └── rubberband
│ ├── RubberBandStretcher.h
│ └── rubberband-c.h
└── lib
├── librubberband.a
└── pkgconfig
└── rubberband.pc
The file rubberband.pc was copied from rubberband.in.pc with some minor changes.
prefix=/path/to/rubberband/install/root
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: rubberband
Version: 1.8.1
Description:
Libs: -L${libdir} -lrubberband -L/path/to/android/ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -lgnustl_static
Cflags: -I${includedir}
Then add
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/path/to/rubberband/install/root
before ./configure to tell ffmpeg find rubberband by pkg-config.
I have tried with the latest ffmpeg, it works.
TL;DR :
Even if libffi seems installed, the configure script doesn't find it even if I give it the (correct?) prefix.
/!\ The last part (*) of this post is where I'm stuck. /!\
I only put the other information to explain how I get there. I apologize for the big post, if something seems irrelevant to you, feel free to tell me, I'll consider making my post shorter.
Why I want to compile CLISP by myself :
I have a lisp programm I would like to run but when running it with CLISP installed with brew (I have no root access) I get the following error :
*** - CFFI requires CLISP compiled with dynamic FFI support.
So I would like to compile CLISP by myself.
I was using SBCL thus far but I had a problem and was looking for an other implementation.
The problems I have when trying to compile :
I downloaded the sources, untared it.
I then trying to run ./configure.
But I get this :
Configure findings:
FFI: no (user requested: default)
readline: no (user requested: default)
libsigsegv: no, consider installing GNU libsigsegv
./configure: libsigsegv was not detected, thus some features, such as
generational garbage collection and
stack overflow detection in interpreted Lisp code
cannot be provided.
Please install libsigsegv like this:
mkdir tools; cd tools; prefix=`pwd`/x86_64-apple-darwin15.4.0
wget http://ftp.gnu.org/pub/gnu/libsigsegv/libsigsegv-2.8.tar.gz
tar xfz libsigsegv-2.8.tar.gz
cd libsigsegv-2.8
./configure --prefix=${prefix} && make && make check && make install
cd ../..
rm -f src/config.cache
./configure --with-libsigsegv-prefix=${prefix}
If you insist on building without libsigsegv, please pass
--ignore-absence-of-libsigsegv
to this script:
./configure --ignore-absence-of-libsigsegv
If you have installed libsigsegv, but clisp does not detect it,
you might have installed it incorrectly, see section 2 in in unix/INSTALL.
IMPORTANT :
libffi and libsigsegv are both installed with homebrew. But aren't found.
I tried adding --with-libsigsegv-prefix=<several values amongst ~/.brew/{opt,opt/libsigsegv,lib,Cellar/libsigsegv,...} : Still the same problem.
This is also almost the same as this post or this one. But the validated solutions doesn't work for me (OSX without root access).
When running configure with --with-dynamic-ffi and --ignore-absence-of-libsigsegv :
I tried to run ./configure --ignore-absence-of-libsigsegv and added --with-dynamic-ffi as someone suggested me in comments.
But then I got this :
Configure findings:
FFI: no (user requested: default)
readline: no (user requested: default)
libsigsegv: no, consider installing GNU libsigsegv
As you requested, we will proceed without libsigsegv...
./makemake --with-dynamic-ffi > Makefile
clang: error: unsupported option '-print-multi-os-directory'
clang: error: no input files
when trying to manually install libffi and libsigsegv :
I also tried the suggestion in the first error message :
When running ./configure --with-libsigsegv-prefix=${prefix} I got :
Configure findings:
FFI: no (user requested: default)
readline: no (user requested: default)
libsigsegv: yes
./makemake --with-libsigsegv-prefix=/nfs/2013/v/vmonteco/Documents/clisp-2.49/tools/x86_64-apple-darwin15.4.0 > Makefile
clang: error: unsupported option '-print-multi-os-directory'
clang: error: no input files
make: `config.lisp' is up to date.
even if I add --with-dynamic-ffi or if I try to install libffi by hand like the first error message suggested (and adding --with-ffi-prefix=${prefix} as well)
If I try to manually build and install libffcall as well :
I get many
avcall-i386.s:7:2: error: instruction requires: Not 64-bit mode
when running make
(*) So now, it does find libsigsegv, but doesn't find libffi.
Yet the tree at ${prefix} looks like this :
.
├── include
│ └── sigsegv.h
├── lib
│ ├── libffi-3.2.1
│ │ └── include
│ │ ├── ffi.h
│ │ └── ffitarget.h
│ ├── libffi.6.dylib
│ ├── libffi.a
│ ├── libffi.dylib -> libffi.6.dylib
│ ├── libffi.la
│ ├── libsigsegv.a
│ ├── libsigsegv.la
│ └── pkgconfig
│ └── libffi.pc
└── share
├── info
│ ├── dir
│ └── libffi.info
└── man
└── man3
├── ffi.3
├── ffi_call.3
├── ffi_prep_cif.3
└── ffi_prep_cif_var.3
I'm out of ideas.
On OSX (and developing for OSX only) it is a very good idea to check Clozure. http://ccl.clozure.com It includes an IDE and from speed and general performance it is comparable to SBCL. You can develop native OSX UI apps using Clozure, of course these will not be portable. If you keep to the standard, then you might even use Clozure on Linux etc.
I am learning CMake but I am struggling to understand how to link a binary file to a shared library and then install these files in a release folder.
These is the structure of my project:
├── CMakeLists.txt
├── build
├── main
│ ├── CMakeLists.txt
│ └── main.cpp
├── release
|_______bin
│ ├── include
│ │ └── math.h
│ └── lib
│ └── libmathLib.dylib
└── shared_lib
├── CMakeLists.txt
├── include
│ └── math.h
└── src
└── math.cpp
In the root CMakeLists.txt I've defined the project settings and the subdirectory.
Root CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
project (Math)
set(CMAKE_BUILD_TYPE Release)
set(MAKE_INCLUDE_CURRENT_DIR ON)
ADD_SUBDIRECTORY(shared_lib)
ADD_SUBDIRECTORY(main)
Main CMakeLists.txt:
add_executable(main main.cpp)
TARGET_LINK_LIBRARIES(main LINK_PUBLIC mathLib)
Math lib ( shared lib )
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_library(mathLib SHARED src/math.cpp)
install(TARGETS mathLib DESTINATION /Users/giuseppe/development/cmake/release/lib LIBRARY NAMELINK_ONLY)
install(FILES include/math.h DESTINATION /Users/giuseppe/development/cmake/release/include)
When I build the project with Make, it doesn't link main.o to the shared library. Error :
Scanning dependencies of target mathLib
[ 50%] Building CXX object shared_lib/CMakeFiles/mathLib.dir/src/math.cpp.o
Linking CXX shared library libmathLib.dylib
[ 50%] Built target mathLib
Scanning dependencies of target main
[100%] Building CXX object main/CMakeFiles/main.dir/main.cpp.o
/Users/giuseppe/development/cmake/main/main.cpp:8:12: error: use of undeclared identifier 'sum'
count << sum(5,6) << endl;
^
1 error generated.
make[2]: *** [main/CMakeFiles/main.dir/main.cpp.o] Error 1
make[1]: *** [main/CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
Release phase:
How can I make sure that the builds in the bin folder within the release folder use the shared lib in 'path/release/lib'? Possibly using a relative path such as '../lib/' ?
You must add include directory for library to main/CMakeLists.txt. Adding it to shared_lib/CMakeLists.txt is not enough. Try this line:
include_directories("../shared_lib/include")
I am trying to build and install a SWIG-generated perl API on OS X 10.10.2. (It's for the FreeLing 3.1 language analysis toolkit.) I have generated and compiled the SWIG files, producing freeling.so.
But when I try to use freeling in a perl script, I get the error:
Can't find 'boot_freeling' symbol in /usr/local/lib/libfreeling.dylib at freeling.pm line 11.
But boot_freeling should be defined in the SWIG-generated freeling.so, not in libfreeling.dylib (the FreeLing package lib). (nm -U confirms this: _boot_freeling is defined in freeling.so; I'm assuming the leading underscore is just part of the object file format.)
I have made sure that freeling.so comes before libfreeling.dylib in LD_LIBRARY_PATH. I've also tried unshifting the path to freeling.so onto #DynaLoader::dl_library_path.
I suspect this is not a path problem, but something about building for OS X. In the past, I have built this on Ubuntu and it works fine. I have tweaked the gcc options (-bundle instead of -shared).
Additional info:
perl -V:dlext => dlext='bundle';
Building SOso-0.01.patch.txt produces:
blib
├── blib/arch
│ └── blib/arch/auto
│ └── blib/arch/auto/SOso
│ └── blib/arch/auto/SOso/SOso.bundle
├── blib/bin
├── blib/lib
│ ├── blib/lib/SOso.pm
│ └── blib/lib/auto
│ └── blib/lib/auto/SOso
├── blib/man1
├── blib/man3
└── blib/script
Makefile target:
freeling.bundle: freeling_perlAPI.cxx
g++ -v -bundle -o freeling.bundle freeling_perlAPI.cxx -lfreeling -lperl -lboost_system -I $(FREELINGDIR)/include -I $(BOOSTDIR)/include -I $(ICU4CDIR)/include -L $(FREELINGDIR)/libfreeling -I $(PERLDIR)/CORE -L $(LIBDIR) -L $(BOOSTDIR)/lib -L $(PERLDIR)/CORE -fPIC
Ok, promoting to answer :)
What do you get for perl -V:dlext ?
When you compile this module SOso-0.01.patch.txt what files are created in blib?
Well :) if your os/perl is configured to look for a freeling.bundle, I don't think its going to try to look at freeling.so .... so I'd try to do something about that ... rename the file to use the dlext