CMakeLists.txt Access GSL Library C - c

Trying to use GSL (Ubuntu 18.04) with CMake.
Installed it according to their INSTALL file:
"sudo sh configure && sudo make && sudo make install"
My Folder Structure:
The GSL header files are located in /gsl-2.5/gsl/
My CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(neuronalnetwork C)
set(CMAKE_C_STANDARD 99)
add_executable(neuronalnetwork main.c)
include_directories(gsl-2.5/gsl)
LINK_DIRECTORIES(gsl-2.5)
target_link_libraries(main.c gsl)
Error:
CMake Error at CMakeLists.txt:11 (target_link_libraries):
Cannot specify link libraries for target "main.c" which is not built by
this project.
If adding target_link_libraries(neuronalnetwork gsl) I get this error:
Update New Error:
/opt/clion/bin/cmake/linux/bin/cmake --build /home/filip/Projekte/neuronalnetwork/cmake-build-debug --target neuronalnetwork -- -j 4
Scanning dependencies of target neuronalnetwork
[ 50%] Building C object CMakeFiles/neuronalnetwork.dir/main.c.o
[100%] Linking C executable neuronalnetwork
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ctrmv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zswap'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zsymm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cgeru'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sgemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ctrsv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sgemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_srotg'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zgemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cdotu_sub'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dznrm2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ddot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_csymm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cher2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zdotu_sub'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sdot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sdsdot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cgerc'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_scnrm2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ctrmm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_strmm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zcopy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsyrk'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cherk'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zherk'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zher'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ztrmv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_drotmg'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dswap'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_scopy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_scasum'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_drotg'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zdotc_sub'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_caxpy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zsyr2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssyr2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_csyr2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ztrsm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ctrsm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssymm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cdotc_sub'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zher2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_saxpy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_idamax'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_snrm2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsdot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cher'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dger'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cher2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dzasum'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsyr2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssyrk'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_strmv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dgemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cgemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dasum'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsymv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_srotm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sswap'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dtrmv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_isamax'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zhemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zaxpy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dcopy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sasum'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsyr'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_strsm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_drot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ztrsv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_izamax'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssymv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_chemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zgeru'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dtrsv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_sger'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_srot'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsymm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ztrmm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zdscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zher2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssyr'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dtrmm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zgerc'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_csscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dsyr2k'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_chemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dnrm2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_drotm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_icamax'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zgemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zhemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cgemv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ssyr2'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_strsv'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dscal'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dgemm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_srotmg'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_dtrsm'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_ccopy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_zsyrk'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_cswap'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_daxpy'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libgsl.so: undefined reference to `cblas_csyrk'
collect2: error: ld returned 1 exit status
Suggestions in other questions didn't work

Your new error message tells you that the blas library, is not found; see the gsl example for the linker flags you need to add.
For more advanced details on how to work with GSL through CMake, look at the FindGSL.cmake file of the eigen project.
More generally, one would usually use GSL as an external dependency, are you sure you want to include it in your code?
EDIT from the comments, you should use GSL as an external dependency, just install it on your system using your linux package manager (look for gsl and make sure to get the header files)
Then, copy the FindGSL.cmake file of eigen, copy it somewhere, then, as they do here run, in your CMakeLists.txt
find_package(GSL)
include_directories(${GSL_INCLUDE_DIR})
Note that if you want to put the .cmake in a specific directory, you will need to tell CMake where to look for it using
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/where/you/put/the/file/)
EDIT 2:
To make it more explicit, here is the full code you need:
cmake_minimum_required(VERSION 3.12)
project(neuronalnetwork C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(GSL)
add_executable(neuronalnetwork main.c)
target_include_directories(neuronalnetwork PRIVATE ${PROJECT_SOURCE_DIR} ${GSL_INCLUDE_DIR})
target_link_libraries(neuronalnetwork ${GSL_LIBRARIES})

Related

CUDD Binary Decision Trees. Linking to libcudd.a

Does anyone on this community have experience with compiling linking the CUDD package for manipulating BDDs? Seems like a great resource if I can only compile something simple... Getting a lot of following.
I am a novice with C, mainly Py guy, so any help would be highly appreciated. (I've tried using tulip-dd in Py, but that is a limited experience). Thanks in advance.
[glarangeira#login1 cudd3]$ gcc basicDD.c
/tmp/cc5v0zuv.o: In function `main':
basicDD.c:(.text+0x2a): undefined reference to `Cudd_Init'
basicDD.c:(.text+0x3a): undefined reference to `Cudd_bddNewVar'
basicDD.c:(.text+0x4a): undefined reference to `Cudd_Ref'
basicDD.c:(.text+0x56): undefined reference to `Cudd_Quit'
collect2: error: ld returned 1 exit status
[glarangeira#login1 cudd3]$ gcc basicDD.c /gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a -o bdd
/gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAPI.o): In function `Cudd_ExpectedUsedSlots':
/gpfs/software/dd/cudd-3.0.0/cudd/cuddAPI.c:1835: undefined reference to `exp'
/gpfs/software/dd/cudd-3.0.0/cudd/cuddAPI.c:1844: undefined reference to `exp'
/gpfs/software/dd/cudd-3.0.0/cudd/cuddAPI.c:1850: undefined reference to `exp'
/gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddCache.o): In function `cuddCacheProfile':
/gpfs/software/dd/cudd-3.0.0/cudd/cuddCache.c:816: undefined reference to `exp'
/gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddUtil.o): In function `Cudd_CountMinterm':
/gpfs/software/dd/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/gpfs/software/dd/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/gpfs/software/dd/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/gpfs/software/dd/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddUtil.o): In function `Cudd_LdblCountMinterm':
/gpfs/software/dd/cudd-3.0.0/cudd/cuddUtil.c:729: undefined reference to `powl'
/gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddUtil.o): In function `Cudd_CountMinterm':
/gpfs/software/dd/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/gpfs/software/dd/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/gpfs/software/dd/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/gpfs/software/dd/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-epd.o): In function `EpdNormalizeDecimal':
/gpfs/software/dd/cudd-3.0.0/epd/epd.c:834: undefined reference to `pow'
/gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-epd.o):/gpfs/software/dd/cudd-3.0.0/epd/epd.c:834: more undefined references to `pow' follow
/gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAnneal.o): In function `siftBackwardProb':
/gpfs/software/dd/cudd-3.0.0/cudd/cuddAnneal.c:671: undefined reference to `exp'
/gpfs/software/dd/cudd-3.0.0/cudd/cuddAnneal.c:671: undefined reference to `exp'
/gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAnneal.o): In function `cuddAnnealing':
/gpfs/software/dd/cudd-3.0.0/cudd/cuddAnneal.c:229: undefined reference to `log'
/gpfs/software/dd/cudd-3.0.0/cudd/cuddAnneal.c:229: undefined reference to `log'
/gpfs/software/dd/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAnneal.o): In function `siftBackwardProb':
/gpfs/software/dd/cudd-3.0.0/cudd/cuddAnneal.c:671: undefined reference to `exp'
collect2: error: ld returned 1 exit status

Compiling pyx files

I've just started to learn cython and this is the first time that I'm trying to compile .pyx files.
I tried to run in my cmd:
Cython fib.pyx
which gave me my fib.c file.
then I run:
gcc -c fib.c -I/Python27/include
which gave me my fib.o file, but when I tried to
gcc -shared fib.o -o fib.so
it gave me this exception:
fib.o:fib.c:(.text+0x72): undefined reference to `_imp__PyObject_GetAttr'
fib.o:fib.c:(.text+0xdb): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0x26c): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0x2ae): undefined reference to `_imp__PyNumber_Add'
fib.o:fib.c:(.text+0x31c): undefined reference to `_imp__PyMethod_Type'
fib.o:fib.c:(.text+0x418): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0x53b): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x543): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x54d): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x79d): undefined reference to `_imp__PyNumber_Add'
fib.o:fib.c:(.text+0x874): undefined reference to `_imp__PyList_Type'
fib.o:fib.c:(.text+0x88b): undefined reference to `_imp__PyTuple_Type'
fib.o:fib.c:(.text+0x8c4): undefined reference to `_imp__PyObject_GetIter'
fib.o:fib.c:(.text+0x972): undefined reference to `_imp__PyList_Type'
fib.o:fib.c:(.text+0xa0b): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0xa1b): undefined reference to `_imp__PyExc_StopIteration'
fib.o:fib.c:(.text+0xa2f): undefined reference to `_imp__PyExc_StopIteration'
fib.o:fib.c:(.text+0xa40): undefined reference to `_imp__PyErr_GivenExceptionMatches'
fib.o:fib.c:(.text+0xa53): undefined reference to `_imp__PyErr_Clear'
fib.o:fib.c:(.text+0xac3): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0xcec): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0xd2e): undefined reference to `_imp__PyNumber_Add'
fib.o:fib.c:(.text+0xd96): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0xe9e): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0xee0): undefined reference to `_imp__PyNumber_Add'
fib.o:fib.c:(.text+0xf48): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0x107c): undefined reference to `_imp__PyMethod_Type'
fib.o:fib.c:(.text+0x11d9): undefined reference to `_imp__PyList_Type'
fib.o:fib.c:(.text+0x11f0): undefined reference to `_imp__PyTuple_Type'
fib.o:fib.c:(.text+0x1229): undefined reference to `_imp__PyObject_GetIter'
fib.o:fib.c:(.text+0x12d7): undefined reference to `_imp__PyList_Type'
fib.o:fib.c:(.text+0x1370): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0x1380): undefined reference to `_imp__PyExc_StopIteration'
fib.o:fib.c:(.text+0x1394): undefined reference to `_imp__PyExc_StopIteration'
fib.o:fib.c:(.text+0x13a5): undefined reference to `_imp__PyErr_GivenExceptionMatches'
fib.o:fib.c:(.text+0x13b8): undefined reference to `_imp__PyErr_Clear'
fib.o:fib.c:(.text+0x1472): undefined reference to `_imp__PyMethod_Type'
fib.o:fib.c:(.text+0x153f): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0x183e): undefined reference to `_imp__PyMethod_Type'
fib.o:fib.c:(.text+0x19c0): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x19c8): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x19d2): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x1c16): undefined reference to `_imp__PyObject_GC_Track'
fib.o:fib.c:(.text+0x1c67): undefined reference to `_imp__PyObject_GC_UnTrack'
fib.o:fib.c:(.text+0x1d5b): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x1d63): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x1d6d): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x1e91): undefined reference to `_imp__PyCode_New'
fib.o:fib.c:(.text+0x1ee1): undefined reference to `_imp__PyTuple_Pack'
fib.o:fib.c:(.text+0x1f31): undefined reference to `_imp__PyTuple_Pack'
fib.o:fib.c:(.text+0x1fd2): undefined reference to `_imp__PyTuple_Pack'
fib.o:fib.c:(.text+0x20a4): undefined reference to `_imp__PyCode_New'
fib.o:fib.c:(.text+0x2185): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0x21cc): undefined reference to `_imp__PyString_FromStringAndSize'
fib.o:fib.c:(.text+0x224f): undefined reference to `_imp__Py_InitModule4'
fib.o:fib.c:(.text+0x22a4): undefined reference to `_imp__PyModule_GetDict'
fib.o:fib.c:(.text+0x22ef): undefined reference to `_imp__PyImport_AddModule'
fib.o:fib.c:(.text+0x2341): undefined reference to `_imp__PyObject_SetAttrString'
fib.o:fib.c:(.text+0x23ae): undefined reference to `_imp__PyObject_SetAttrString'
fib.o:fib.c:(.text+0x2423): undefined reference to `_imp__PyType_Ready'
fib.o:fib.c:(.text+0x24bf): undefined reference to `_imp__PyDict_SetItem'
fib.o:fib.c:(.text+0x252b): undefined reference to `_imp__PyCFunction_NewEx'
fib.o:fib.c:(.text+0x2577): undefined reference to `_imp__PyDict_SetItem'
fib.o:fib.c:(.text+0x25cb): undefined reference to `_imp__PyDict_New'
fib.o:fib.c:(.text+0x2614): undefined reference to `_imp__PyDict_SetItem'
fib.o:fib.c:(.text+0x26fe): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0x2709): undefined reference to `_imp__PyExc_ImportError'
fib.o:fib.c:(.text+0x271b): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x2756): undefined reference to `_imp__PyExc_NameError'
fib.o:fib.c:(.text+0x276c): undefined reference to `_imp__PyErr_Format'
fib.o:fib.c:(.text+0x278d): undefined reference to `_imp__PyDict_GetItem'
fib.o:fib.c:(.text+0x27fb): undefined reference to `_imp__PyObject_Call'
fib.o:fib.c:(.text+0x2807): undefined reference to `_imp___PyThreadState_Current'
fib.o:fib.c:(.text+0x281a): undefined reference to `_imp___Py_CheckRecursionLimit'
fib.o:fib.c:(.text+0x2834): undefined reference to `_imp___Py_CheckRecursiveCall'
fib.o:fib.c:(.text+0x286a): undefined reference to `_imp___PyThreadState_Current'
fib.o:fib.c:(.text+0x2888): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0x289b): undefined reference to `_imp__PyExc_SystemError'
fib.o:fib.c:(.text+0x28ad): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x28d4): undefined reference to `_imp___PyThreadState_Current'
fib.o:fib.c:(.text+0x28e7): undefined reference to `_imp___Py_CheckRecursionLimit'
fib.o:fib.c:(.text+0x2901): undefined reference to `_imp___Py_CheckRecursiveCall'
fib.o:fib.c:(.text+0x2930): undefined reference to `_imp___PyThreadState_Current'
fib.o:fib.c:(.text+0x294e): undefined reference to `_imp__PyErr_Occurred'
fib.o:fib.c:(.text+0x2961): undefined reference to `_imp__PyExc_SystemError'
fib.o:fib.c:(.text+0x2973): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x298c): undefined reference to `_imp__PyTuple_New'
fib.o:fib.c:(.text+0x2a16): undefined reference to `_imp__PyCFunction_Type'
fib.o:fib.c:(.text+0x2a51): undefined reference to `_imp__PyType_IsSubtype'
fib.o:fib.c:(.text+0x2ac8): undefined reference to `_imp__PyImport_AddModule'
fib.o:fib.c:(.text+0x2aff): undefined reference to `_imp__PyObject_GetAttrString'
fib.o:fib.c:(.text+0x2b22): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2b38): undefined reference to `_imp__PyErr_Format'
fib.o:fib.c:(.text+0x2b5e): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2b74): undefined reference to `_imp__PyErr_Format'
fib.o:fib.c:(.text+0x2b80): undefined reference to `_imp__PyExc_AttributeError'
fib.o:fib.c:(.text+0x2b8a): undefined reference to `_imp__PyErr_ExceptionMatches'
fib.o:fib.c:(.text+0x2b97): undefined reference to `_imp__PyErr_Clear'
fib.o:fib.c:(.text+0x2ba4): undefined reference to `_imp__PyType_Ready'
fib.o:fib.c:(.text+0x2bc8): undefined reference to `_imp__PyObject_SetAttrString'
fib.o:fib.c:(.text+0x2c7d): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0x2ca5): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x2caf): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x2cb6): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x2ce7): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x2d5c): undefined reference to `_imp__PyString_InternFromString'
fib.o:fib.c:(.text+0x2dc7): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2dd9): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x2e80): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2e92): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x2f08): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x2f3a): undefined reference to `_imp__PyDict_New'
fib.o:fib.c:(.text+0x2f8b): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2f9d): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x2fc8): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x2fda): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x3056): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3060): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3067): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3086): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x313d): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3147): more undefined references to `_imp___Py_NoneStruct' follow
fib.o:fib.c:(.text+0x3163): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x3175): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x321e): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3244): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x324e): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x326a): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x327c): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x3325): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x334b): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3370): undefined reference to `_imp__PyExc_TypeError'
fib.o:fib.c:(.text+0x3382): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x3406): undefined reference to `_imp__PyDict_New'
fib.o:fib.c:(.text+0x3451): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0x3466): undefined reference to `_imp___PyObject_GC_New'
fib.o:fib.c:(.text+0x358f): undefined reference to `_imp__PyObject_GC_Track'
fib.o:fib.c:(.text+0x3969): undefined reference to `_imp__PyMem_Free'
fib.o:fib.c:(.text+0x398d): undefined reference to `_imp__PyObject_GC_UnTrack'
fib.o:fib.c:(.text+0x39a4): undefined reference to `_imp__PyObject_ClearWeakRefs'
fib.o:fib.c:(.text+0x39bc): undefined reference to `_imp__PyObject_GC_Del'
fib.o:fib.c:(.text+0x3cab): undefined reference to `_imp__PyMethod_New'
fib.o:fib.c:(.text+0x3cb4): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x3cd9): undefined reference to `_imp__PyMethod_New'
fib.o:fib.c:(.text+0x3cf1): undefined reference to `_imp__PyString_AsString'
fib.o:fib.c:(.text+0x3d0c): undefined reference to `_imp__PyString_FromFormat'
fib.o:fib.c:(.text+0x3d2f): undefined reference to `_imp__PyCFunction_Call'
fib.o:fib.c:(.text+0x3d3e): undefined reference to `_imp__PyCFunction_Call'
fib.o:fib.c:(.text+0x3d7c): undefined reference to `_imp__PyCFunction_Type'
fib.o:fib.c:(.text+0x3db7): undefined reference to `_imp__PyType_IsSubtype'
fib.o:fib.c:(.text+0x3e81): undefined reference to `_imp__PyList_New'
fib.o:fib.c:(.text+0x3ea4): undefined reference to `_imp__PyModule_GetDict'
fib.o:fib.c:(.text+0x3eb9): undefined reference to `_imp__PyDict_New'
fib.o:fib.c:(.text+0x3eda): undefined reference to `_imp__PyInt_FromLong'
fib.o:fib.c:(.text+0x3f1d): undefined reference to `_imp__PyObject_CallFunctionObjArgs'
fib.o:fib.c:(.text+0x4182): undefined reference to `_imp__PyMem_Malloc'
fib.o:fib.c:(.text+0x42b0): undefined reference to `_imp__PyMem_Realloc'
fib.o:fib.c:(.text+0x438a): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0x43c3): undefined reference to `_imp__PyString_FromFormat'
fib.o:fib.c:(.text+0x43d5): undefined reference to `_imp__PyString_FromString'
fib.o:fib.c:(.text+0x4469): undefined reference to `_imp__PyCode_New'
fib.o:fib.c:(.text+0x45ae): undefined reference to `_imp___PyThreadState_Current'
fib.o:fib.c:(.text+0x45cb): undefined reference to `_imp__PyFrame_New'
fib.o:fib.c:(.text+0x45ec): undefined reference to `_imp__PyTraceBack_Here'
fib.o:fib.c:(.text+0x465c): undefined reference to `_imp__PySys_GetObject'
fib.o:fib.c:(.text+0x466c): undefined reference to `_imp__PyExc_RuntimeError'
fib.o:fib.c:(.text+0x467e): undefined reference to `_imp__PyErr_SetString'
fib.o:fib.c:(.text+0x46d5): undefined reference to `_imp__PyFile_SoftSpace'
fib.o:fib.c:(.text+0x46ee): undefined reference to `_imp__PyFile_WriteString'
fib.o:fib.c:(.text+0x4720): undefined reference to `_imp__PyFile_WriteObject'
fib.o:fib.c:(.text+0x4748): undefined reference to `_imp__PyString_AsString'
fib.o:fib.c:(.text+0x4758): undefined reference to `_imp__PyString_Size'
fib.o:fib.c:(.text+0x4798): undefined reference to `_imp__PyFile_SoftSpace'
fib.o:fib.c:(.text+0x47cc): undefined reference to `_imp__PyFile_WriteString'
fib.o:fib.c:(.text+0x47e7): undefined reference to `_imp__PyFile_SoftSpace'
fib.o:fib.c:(.text+0x4889): undefined reference to `_imp__PyFile_SoftSpace'
fib.o:fib.c:(.text+0x48a2): undefined reference to `_imp__PyFile_WriteString'
fib.o:fib.c:(.text+0x48c4): undefined reference to `_imp__PyFile_WriteObject'
fib.o:fib.c:(.text+0x48df): undefined reference to `_imp__PyFile_WriteString'
fib.o:fib.c:(.text+0x4977): undefined reference to `_imp__PyOS_snprintf'
fib.o:fib.c:(.text+0x497e): undefined reference to `_imp__Py_GetVersion'
fib.o:fib.c:(.text+0x499f): undefined reference to `_imp__PyOS_snprintf'
fib.o:fib.c:(.text+0x49ed): undefined reference to `_imp__PyOS_snprintf'
fib.o:fib.c:(.text+0x4a0d): undefined reference to `_imp__PyErr_WarnEx'
fib.o:fib.c:(.text+0x4a57): undefined reference to `_imp__PyUnicodeUCS2_DecodeUTF8'
fib.o:fib.c:(.text+0x4a7b): undefined reference to `_imp__PyString_InternFromString'
fib.o:fib.c:(.text+0x4aa1): undefined reference to `_imp__PyString_FromStringAndSize'
fib.o:fib.c:(.text+0x4afe): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b0e): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b1a): undefined reference to `_imp__PyType_IsSubtype'
fib.o:fib.c:(.text+0x4b2f): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b3f): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b4b): undefined reference to `_imp__PyType_IsSubtype'
fib.o:fib.c:(.text+0x4b83): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b93): undefined reference to `_imp__PyByteArray_Type'
fib.o:fib.c:(.text+0x4b9f): undefined reference to `_imp__PyType_IsSubtype'
fib.o:fib.c:(.text+0x4bd8): undefined reference to `_imp___PyByteArray_empty_string'
fib.o:fib.c:(.text+0x4bf3): undefined reference to `_imp__PyString_AsStringAndSize'
fib.o:fib.c:(.text+0x4c1c): undefined reference to `_imp___Py_TrueStruct'
fib.o:fib.c:(.text+0x4c2d): undefined reference to `_imp___Py_ZeroStruct'
fib.o:fib.c:(.text+0x4c40): undefined reference to `_imp___Py_NoneStruct'
fib.o:fib.c:(.text+0x4c5f): undefined reference to `_imp__PyObject_IsTrue'
collect2.exe: error: ld returned 1 exit status
I'll be grateful for any help.
I always compile my cython with one line of gcc:
gcc -shared -Wall -O3 -I Python27/include -L Python27/libs -o fib.so fib.c -l python27
You see, including the header files (-I) for python isn't enough. You also have to include the location of python's libraries (-L), and then the name of the file to use as that library (-l).
Happy Cythonizing!
There is another solution that might come in handy with bigger projects. Instead of writing yourself the gcc call in the command line you can create a configuration file in python that cython will use to autogenerate C or C++ code and call the gcc compiler with the appropriate flags.
Simply create a file setup.py (or a filename of your preference). Then fill it with:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
ext = Extension("fib",
sources=["fib.pyx"],
language="c++",
include_dirs=[],
libraries=[],
extra_link_args=[])
setup(ext_modules = cythonize([ext]))
Then in the terminal python setup.py build_ext --inplace.
This will generate a fib.cpp file and compile it to the shared object file fib.so as well as an object file fib.o (this last in a folder called build).
After that, you can already import fib in your *.py files.

"undefined reference" when trying to use lp_solve in C/C++ on Linux

I'm new to linear programming and C. I am trying to use the lp_solve library to solve a linear equation. The problem is I can't get the demo code to work.
As described in the documentation, I downloaded lp_solve_5.5_dev.gz to my Linux machine. I extracted the files into the same folder as my code and tried to compile:
~/Desktop/Code/CA$ cc -o demo demo.c
/tmp/ccpeN8ZV.o: In function `demo':
demo.c:(.text+0x31): undefined reference to `make_lp'
demo.c:(.text+0x62): undefined reference to `set_col_name'
demo.c:(.text+0x7d): undefined reference to `set_col_name'
demo.c:(.text+0xcf): undefined reference to `set_add_rowmode'
demo.c:(.text+0x150): undefined reference to `add_constraintex'
demo.c:(.text+0x1e6): undefined reference to `add_constraintex'
demo.c:(.text+0x274): undefined reference to `add_constraintex'
demo.c:(.text+0x29c): undefined reference to `set_add_rowmode'
demo.c:(.text+0x30b): undefined reference to `set_obj_fnex'
demo.c:(.text+0x327): undefined reference to `set_maxim'
demo.c:(.text+0x33b): undefined reference to `write_LP'
demo.c:(.text+0x34e): undefined reference to `set_verbose'
demo.c:(.text+0x359): undefined reference to `solve'
demo.c:(.text+0x383): undefined reference to `get_objective'
demo.c:(.text+0x3a6): undefined reference to `get_variables'
demo.c:(.text+0x3d2): undefined reference to `get_col_name'
demo.c:(.text+0x429): undefined reference to `delete_lp'
collect2: ld returned 1 exit status
When I add liblpsolve55.a to the command I get the following errors:
~/Desktop/Code/CA$ cc -o demo demo.c liblpsolve55.a
liblpsolve55.a(lp_lib.o): In function `scaled_floor':
lp_lib.c:(.text+0x6923): undefined reference to `floor'
liblpsolve55.a(lp_lib.o): In function `scaled_ceil':
lp_lib.c:(.text+0x6f03): undefined reference to `ceil'
liblpsolve55.a(lp_lib.o): In function `set_XLI':
lp_lib.c:(.text+0x7aa2): undefined reference to `dlclose'
lp_lib.c:(.text+0x7bb3): undefined reference to `dlopen'
lp_lib.c:(.text+0x7bd1): undefined reference to `dlsym'
lp_lib.c:(.text+0x7d8a): undefined reference to `dlsym'
lp_lib.c:(.text+0x7da6): undefined reference to `dlsym'
lp_lib.c:(.text+0x7dc2): undefined reference to `dlsym'
liblpsolve55.a(lp_lib.o): In function `set_BFP':
lp_lib.c:(.text+0x7eb4): undefined reference to `dlclose'
lp_lib.c:(.text+0x7fc3): undefined reference to `dlopen'
lp_lib.c:(.text+0x7fe1): undefined reference to `dlsym'
lp_lib.c:(.text+0x831a): undefined reference to `dlsym'
lp_lib.c:(.text+0x8336): undefined reference to `dlsym'
lp_lib.c:(.text+0x8352): undefined reference to `dlsym'
lp_lib.c:(.text+0x836e): undefined reference to `dlsym'
liblpsolve55.a(lp_lib.o):lp_lib.c:(.text+0x838a): more undefined references to `dlsym' follow
................
I understand that the lp_solve libraries are not loaded in my code. Can you please tell me how I can properly link the lp_solve libraries?
You're just missing some compiler flags to include the proper libraries. As danielko said, a quick google search on the missing libraries brings up some suggestions. E.g.
Linux c++ error: undefined reference to 'dlopen'
http://sourceforge.net/p/dev-cpp/discussion/48211/thread/3bd8b8a1
These suggest your compilation should be something more like:
cc -o demo demo.c -ldl -llpsolve55
and the lpsolve documentation suggests a command that includes the project directory such as:
cc -I/lp_solve_5.5 -I/lp_solve_5.5/bfp -I/lp_solve_5.5/bfp/bfp_etaPFI -I/lp_solve_5.5/colamd $src -o MyExe.exe -lm -ldl

Undefined references when compiling SDL project with MingW (NOT WinMain error)

I've been going a bit crazy trying to figure out the issue here. My project builds fine on Fedora with it's native gcc and pkg-config flags but when cross-compiling or using MingW on Windows it gives me undefined references. The oddest thing was, I remember getting it to compile once or twice on Windows but I have no idea how. As far as I know, all the libraries are accessible, so I can't figure out what's wrong.
With this input:
mingw32-gcc -std=c99 -g -LC:/MinGW/lib -mwindows -lSDL -lSDLmain -lfreetype -lmingw32 -lglu32 -lopengl32 -o bin/gltris.exe gltris.o graphics.o input.o game.o block.o timer.o text.o
I get this output: (sorry for the weird formatting)
C:/MinGW/lib/libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain#16'
gltris.o: In function `gltris_init':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/gltris.c:24: undefined reference to `SDL_Init'
gltris.o: In function `SDL_main':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/gltris.c:110: undefined reference to `SDL_Quit'
graphics.o: In function `graphics_init':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:31: undefined reference to `SDL_SetVideoMode'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:34: undefined reference to `glClearColor#16'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:35: undefined reference to `glClear#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:36: undefined reference to `glViewport#16'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:38: undefined reference to `glMatrixMode#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:39: undefined reference to `glLoadIdentity#0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:40: undefined reference to `glDisable#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:41: undefined reference to `glBlendFunc#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:42: undefined reference to `glPixelStorei#8'
graphics.o: In function `graphics_begin_frame':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:50: undefined reference to `glMatrixMode#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:51: undefined reference to `glLoadIdentity#0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:52: undefined reference to `glClear#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:54: undefined reference to `gluOrtho2D#32'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:56: undefined reference to `glMatrixMode#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:57: undefined reference to `glLoadIdentity#0'
graphics.o: In function `graphics_end_frame':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:62: undefined reference to `SDL_GL_SwapBuffers'
graphics.o: In function `graphics_render_block':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:68: undefined reference to `glPushMatrix#0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:70: undefined reference to `glTranslatef#12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:71: undefined reference to `glScalef#12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:74: undefined reference to `glColor4ub#16'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:76: undefined reference to `glColor3ubv#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:78: undefined reference to `glEnable#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:81: undefined reference to `glBegin#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:82: undefined reference to `glVertex2i#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:83: undefined reference to `glVertex2i#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:84: undefined reference to `glVertex2i#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:85: undefined reference to `glVertex2i#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:86: undefined reference to `glEnd#0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:88: undefined reference to `glDisable#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:90: undefined reference to `glPopMatrix#0'
graphics.o: In function `render_textured_quad':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:165: undefined reference to `glPushMatrix#0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:167: undefined reference to `glEnable#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:168: undefined reference to `glEnable#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:169: undefined reference to `glBindTexture#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:171: undefined reference to `glTranslatef#12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:173: undefined reference to `glBegin#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:175: undefined reference to `glTexCoord2f#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:176: undefined reference to `glVertex2f#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:178: undefined reference to `glTexCoord2f#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:179: undefined reference to `glVertex2f#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:181: undefined reference to `glTexCoord2f#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:182: undefined reference to `glVertex2f#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:184: undefined reference to `glTexCoord2f#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:185: undefined reference to `glVertex2f#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:187: undefined reference to `glEnd#0'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:189: undefined reference to `glDisable#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:190: undefined reference to `glDisable#4'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:192: undefined reference to `glPopMatrix#0'
graphics.o: In function `surface_to_texture':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:212: undefined reference to `glGenTextures#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:213: undefined reference to `glBindTexture#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:214: undefined reference to `glTexParameteri#12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:215: undefined reference to `glTexParameteri#12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:216: undefined reference to `glTexImage2D#36'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/graphics.c:221: undefined reference to `SDL_FreeSurface'
input.o: In function `handle_input':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/input.c:13: undefined reference to `SDL_PollEvent'
timer.o: In function `add_timer':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:20: undefined reference to `SDL_GetTicks'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:36: undefined reference to `SDL_GetTicks'
timer.o: In function `do_timers':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:65: undefined reference to `SDL_GetTicks'
timer.o: In function `pause_timer':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:84: undefined reference to `SDL_GetTicks'
timer.o: In function `resume_timer':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:90: undefined reference to `SDL_GetTicks'
timer.o:C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/timer.c:98: more undefined references to `SDL_GetTicks' follow
text.o: In function `text_init':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:24: undefined reference to `_imp__FT_Init_FreeType'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:28: undefined reference to `_imp__FT_New_Face'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:32: undefined reference to `_imp__FT_Set_Char_Size'
text.o: In function `text_gen_texture':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:70: undefined reference to `glGenTextures#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:71: undefined reference to `glBindTexture#8'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:72: undefined reference to `glTexParameteri#12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:73: undefined reference to `glTexParameteri#12'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:77: undefined reference to `glTexImage2D#36'
text.o: In function `text_print':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:92: undefined reference to `_imp__FT_Set_Char_Size'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:97: undefined reference to `_imp__FT_Load_Char'
text.o: In function `get_text_size':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:115: undefined reference to `_imp__FT_Set_Char_Size'
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:119: undefined reference to `_imp__FT_Load_Char'
text.o: In function `print_game_info':
C:\MinGW\msys\1.0\home\Max\gltris-unstable/src/text.c:138: undefined reference to `glColor3f#12'
collect2.exe: error: ld returned 1 exit status
EDIT:I got it to build by compiling and linking in one go, with the linker flags "-lmingw32 -lopengl32 -lSDLmain -lSDL -lfreetype -mwindows"
It seems like your compiler cannot find libSDL.a and other library files. Check if libSDL.a is present in C:/MinGW/lib. You will need a libSDL.a that is specifically made for mingw.
Also, try compiling a simple "Hello World" SDL program. That will make it easier to find what the error is.

error in SD card program

i run sd card program in linux but i found following error....but i include header file also
anish#ubuntu:~/Desktop/testing/sd card$ gcc -o sdcard sdcard.c
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
/tmp/ccVMCgzn.o: In function `SDCardInit':
sdcard.c:(.text+0x23): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x4d): undefined reference to `SPI1Send'
sdcard.c:(.text+0x8b): undefined reference to `SPI1Byte'
sdcard.c:(.text+0xb2): undefined reference to `SPI1Send'
sdcard.c:(.text+0xfd): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x102): undefined reference to `CRC16Bit_GenTable'
/tmp/ccVMCgzn.o: In function `SDResponseMatch':
sdcard.c:(.text+0x128): undefined reference to `SPI1Byte'
/tmp/ccVMCgzn.o: In function `SDResponseDontMatch':
sdcard.c:(.text+0x162): undefined reference to `SPI1Byte'
/tmp/ccVMCgzn.o: In function `SDWriteBlock':
sdcard.c:(.text+0x1db): undefined reference to `CRC_7Bit'
sdcard.c:(.text+0x202): undefined reference to `SPI1Send'
sdcard.c:(.text+0x23b): undefined reference to `CRC_16Bit'
sdcard.c:(.text+0x24a): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x25d): undefined reference to `SPI1Send'
sdcard.c:(.text+0x26b): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x27b): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x287): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x2f7): undefined reference to `SPI1Byte'
/tmp/ccVMCgzn.o: In function `SDReadBlockPart':
sdcard.c:(.text+0x35e): undefined reference to `CRC_7Bit'
sdcard.c:(.text+0x388): undefined reference to `SPI1Send'
sdcard.c:(.text+0x3f0): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x3ff): undefined reference to `CRC_16Bit_AddByte'
sdcard.c:(.text+0x41c): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x43b): undefined reference to `CRC_16Bit_AddByte'
sdcard.c:(.text+0x463): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x472): undefined reference to `CRC_16Bit_AddByte'
sdcard.c:(.text+0x48e): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x4a0): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x4d6): undefined reference to `SPI1Byte'
/tmp/ccVMCgzn.o: In function `SDWriteBlockHead':
sdcard.c:(.text+0x53c): undefined reference to `CRC_7Bit'
sdcard.c:(.text+0x563): undefined reference to `SPI1Send'
sdcard.c:(.text+0x59b): undefined reference to `CRC_16Bit'
s dcard.c:(.text+0x5aa): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x5ca): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x5f0): undefined reference to `CRC_16Bit_AddByte'
sdcard.c:(.text+0x5ff): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x616): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x626): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x632): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x6a2): undefined reference to `SPI1Byte'
/tmp/ccVMCgzn.o: In function `SDWriteMultiBlock':
sdcard.c:(.text+0x702): undefined reference to `CRC_7Bit'
sdcard.c:(.text+0x729): undefined reference to `SPI1Send'
sdcard.c:(.text+0x76e): undefined reference to `CRC_16Bit'
sdcard.c:(.text+0x77d): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x790): undefined reference to `SPI1Send'
sdcard.c:(.text+0x7a5): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x7b5): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x7c1): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x7fa): undefined reference to `SPI1Byte'
sdcard.c:(.text+0x847): undefined reference to `SPI1Byte'
Looks like to me your forgot to link a couple of libraries.
or if you want to generate an object file to link it afterwards, this would be better
gcc -o sdcard.o sdcard.c
crt1.o is the C Runtime. It specifies where to start the program and few other things. Execution starts at _start symbol and then jumps to the main defined in the program. So from error
In function `_start':
(.text+0x18): undefined reference to `main'
my guess is that you may have misspelled your main function, may be you have named it Main or something else.
For other errors, you will need to link with the library that provides these functions or, if you are using functions in other source files, you will need to compile them too then link all of these files together.

Resources