I'm trying to build simple dll which uses library UMFPACK.
Here is my file "umfsolver.c":
#include <stdio.h>
#include <stdlib.h>
#include "umfpack.h"
#include "amd.h"
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#ifdef BUILD_DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif
typedef struct problem_struct
{
double Control [UMFPACK_CONTROL];
double Info [UMFPACK_INFO];
int *Ti;
int *Tj;
double *Tx;
int nrow;
int ncol;
int nz;
} problem;
EXPORT problem* __stdcall create(int nrows, int ncols, int nnonzero)
{
problem *prob;
prob = (problem*) malloc(sizeof (problem)) ;
if (!prob) return (NULL);
prob->nrow = nrows;
prob->ncol = ncols;
prob->nz = nnonzero;
printf("Creating...\n");
umfpack_di_defaults (prob->Control) ;
prob->Control [UMFPACK_PRL] = 3 ;
prob->Control [UMFPACK_BLOCK_SIZE] = 32 ;
prob->Ti = (int *) malloc (nnonzero * sizeof (int)) ;
prob->Tj = (int *) malloc (nnonzero * sizeof (int)) ;
prob->Tx = (double *) malloc (nnonzero * sizeof (double)) ;
if (!prob->Ti || !prob->Tj || !prob->Tx ) return (NULL);
return prob;
}
And here is my makefile:
all: libs umfsolver
include ../../SuiteSparse_config/SuiteSparse_config.mk
#-------------------------------------------------------------------------------
# the optional Partition module requires METIS, CAMD, and CCOLAMD
I_WITH_PARTITION =
LIB_WITH_PARTITION =
CONFIG1 = -DNCHOLMOD
CONFIG2 = -DNPARTITION
ifeq (,$(findstring -DNCHOLMOD, $(UMFPACK_CONFIG)))
# CHOLMOD is requested. See if it is available
ifeq (../../CHOLMOD, $(wildcard ../../CHOLMOD))
ifeq (../../COLAMD, $(wildcard ../../COLAMD))
# CHOLMOD and COLAMD are available
CONFIG1 =
LIB_WITH_CHOLMOD = ../../CHOLMOD/Lib/libcholmod.a \
../../COLAMD/Lib/libcolamd.a
# check if METIS is requested and available
ifeq (,$(findstring -DNPARTITION, $(CHOLMOD_CONFIG)))
# METIS is requested. See if it is available
ifeq ($(METIS_PATH), $(wildcard $(METIS_PATH)))
ifeq (../../CAMD, $(wildcard ../../CAMD))
ifeq (../../CCOLAMD, $(wildcard ../../CCOLAMD))
# METIS, CAMD, and CCOLAMD are available
LIB_WITH_PARTITION = $(METIS) \
../../CCOLAMD/Lib/libccolamd.a \
../../CAMD/Lib/libcamd.a
I_WITH_PARTITION = -I$(METIS_PATH)/Lib \
-I../../CCOLAMD/Include -I../../CAMD/Include
CONFIG2 =
endif
endif
endif
endif
endif
endif
endif
#-------------------------------------------------------------------------------
C = $(CC) $(CF) $(UMFPACK_CONFIG) $(CONFIG1) $(CONFIG2) \
-I../Include -I../../AMD/Include -I../../SuiteSparse_config
INC = ../Include/umfpack.h ../../AMD/Include/amd.h ../../SuiteSparse_config/SuiteSparse_config.h
LIBS = $(LAPACK) $(BLAS) $(XERBLA) $(LIB) $(LIB_WITH_CHOLMOD) $(LIB_WITH_PARTITION) $(CUBLAS_LIB) $(CUDART_LIB)
../Lib/libumfpack.a:
( cd ../Lib ; $(MAKE) )
../../AMD/Lib/libamd.a:
( cd ../../AMD ; $(MAKE) library )
../../SuiteSparse_config/libsuitesparseconfig.a:
( cd ../../SuiteSparse_config ; $(MAKE) library )
../../CHOLMOD/Lib/libcholmod.a:
- ( cd ../../CHOLMOD && $(MAKE) library )
../../COLAMD/Lib/libcolamd.a:
- ( cd ../../COLAMD && $(MAKE) library )
../../CCOLAMD/Lib/libccolamd.a:
- ( cd ../../CCOLAMD && $(MAKE) library )
../../CAMD/Lib/libcamd.a:
- ( cd ../../CAMD && $(MAKE) library )
$(METIS):
( cd $(METIS_PATH) && $(MAKE) )
UMFPACK = ../Lib/libumfpack.a ../../AMD/Lib/libamd.a \
../../SuiteSparse_config/libsuitesparseconfig.a \
$(LIB_WITH_CHOLMOD) $(LIB_WITH_PARTITION)
libs: $(UMFPACK)
umfsolver: umfsolver.c $(UMFPACK)
$(C) -c -DBUILD_DLL umfsolver.c
$(C) -shared -o umfsolver.dll umfsolver.o -Wl,--add-stdcall-alias $(UMFPACK) $(LIBS) -lm
I used variables:
CF = -O3 -fexceptions -fPIC
CC = cc
LIB = -lm -lrt
UMFPACK_CONFIG = -DNBLAS -LD:/SuiteSparseBuild/UMFPACK/Lib -lsuitesparseconfig -lrt
MAKE = make
CUBLAS_LIB =
CUDART_LIB =
XERBLA =
BLAS =
LAPACK =
METIS_PATH = ../../metis-4.0
METIS = ../../metis-4.0/libmetis.a
It builds with no errors. When I'm calling function create from another program (using static dllimport), it works until some library function need to be called inside create.
It seems like the program goes to infinite loop when either it calls printf("Creating...\n") or umfpack_di_defaults (prob->Control).
When I type make, I get this:
cc -O3 -fexceptions -fPIC -DNBLAS -LD:/SuiteSparseBuild/UMFPACK/Lib -lsuitesparseconfig -lrt -I../Include -I../../AMD/Include -I../../SuiteSparse_config -c -DBUILD_DLL umfsolver.c
cc1: warning: fPIC ignored for target (all code is position independent)
cc -O3 -fexceptions -fPIC -DNBLAS -LD:/SuiteSparseBuild/UMFPACK/Lib -lsuitesparseconfig -lrt -I../Include -I../../AMD/Include -I../../SuiteSparse_config -shared -o umfsolver.dll umfsolver.o ../Lib/libumfpack.a ../../AMD/Lib/libamd.a ../../SuiteSparse_config/libsuitesparseconfig.a ../../CHOLMOD/Lib/libcholmod.a ../../COLAMD/Lib/libcolamd.a ../../metis-4.0/libmetis.a ../../CCOLAMD/Lib/libccolamd.a ../../CAMD/Lib/libcamd.a -lm -lrt ../../CHOLMOD/Lib/libcholmod.a ../../COLAMD/Lib/libcolamd.a ../../metis-4.0/libmetis.a ../../CCOLAMD/Lib/libccolamd.a ../../CAMD/Lib/libcamd.a -Wl,--add-stdcall-alias
I guess that I should somehow change the makefile to put all library files together?
How can I do this? Can anyone explain me this?
Thanks!
Related
I defined the next two static functions in a file named Grafico.h.
static inline interface_t * obtener_intf_por_nombre(nodo_t *nodo, char *nombre_if) {
for (int i = 0; i < MAX_INTF_POR_NODO; ++i)
{
if(!nodo->intf[i]) return NULL;
if(strncmp(nodo->intf[i]->nombre_if, nombre_if, TAM_NOMBRE_IF) == 0) {
return nodo->intf[i];
}
}
return NULL;
}
static inline nodo_t * obtener_nodo_por_nombre(grafico_t *topologia, char *nombre_nodo) {
return obtener_elemento(topologia->lista_nodos, nombre_nodo);
}
In my main file I called these functions without remembering they were static, and I didn't get any warning or error from the compiler related to it.
#include <stdio.h>
#include "Net.h"
#include "Grafico.h"
#include "Topologias.h"
#include "CommandParser/libcli.h"
#include "clired.c"
extern grafico_t *const_primera_topo();
grafico_t *topo = NULL;
int main(void) {
inic_cli_red();
topo = const_primera_topo();
sleep(2);
nodo_t *nodo_trans = obtener_nodo_por_nombre(topo, "R0");
interface_t *interface_trans = obtener_intf_por_nombre(nodo_trans, "ethR0/0");
char *mensaje = "Este es un mensaje de prueba\0";
printf("Llegamos hasta aquí señores. Fue un honor.\n");
enviar_paquete(mensaje, strlen(mensaje), interface_trans);
start_shell();
return 0;
}
In case it's useful, here is my makefile.
TARGET = $(BIN_DIR)/sim_tcp_ip
LIBS = -lpthread -L ./CommandParser -lcli -lrt
OBJS = $(OBJ_DIR)/prueba.o \
$(OBJ_DIR)/ListaEnlazadaGenerica.o \
$(OBJ_DIR)/Grafico.o \
$(OBJ_DIR)/Net.o \
$(OBJ_DIR)/Topologias.o \
$(OBJ_DIR)/Com.o \
$(OBJ_DIR)/Utiles.o \
$(OBJ_DIR)/Capa2.o
BIN_DIR = ./bin
OBJ_DIR = ./obj
INC_DIR = ./inc
SRC_DIR = ./src
CFLAGS = -g -lpthread -Wall -I$(INC_DIR)
$(TARGET): $(OBJS) CommandParser/libcli.a
mkdir -p $(BIN_DIR)
gcc $(CFLAGS) $(OBJS) -o $(TARGET) $(LIBS)
$(OBJ_DIR)/%.o : %.c
mkdir -p $(OBJ_DIR)
gcc -c -MD $(CFLAGS) $< -o $#
CommandParser/libcli.a:
(cd CommandParser; make)
-include $(OBJ_DIR)/*.d
.PHONY: clean
clean:
rm -rf $(OBJ_DIR) $(BIN_DIR)
(cd CommandParser; make clean)
all:
make
Is there something wrong with the definition of these static functions?
When you #include a file, it is equivalent to copypasting the contents of that file in place of that line. So the static functions are in the same compilation unit, and hence just as usable as any other static thing you define in the .c file itself.
The problem is that you have declared them in your header file, Graphico.h!
The static keyword just means that if you compile a source C file prog.c into an object file prog.o, then any static functions in prog.c will be hard coded as memory addresses in prog.o. That is to say, whereas a normal function has an entry defined in the symbol table of prog.o, that is used when prog.o is linked with another object file, a static function does not.
I am compiling a program meant for the Unix-like OS to windows with msys2 using GCC
program source: repository of the program,
then this error popped up,
src/gfx/../util/time.h:12:27: error: 'TIME_UTC' undeclared (first use in this function); did you mean 'TIME_H'?
12 | timespec_get(&ts, TIME_UTC);
| ^~~~~~~~
| TIME_H
How do I fix this
also here is my MakeFile:
UNAME_S = $(shell uname -s)
CC = gcc
CFLAGS = -std=c11 -O3 -g -Wall -Wextra -Wpedantic -Wstrict-aliasing -fdiagnostics-color
CFLAGS += -Wno-pointer-arith -Wno-newline-eof -Wno-unused-parameter -Wno-gnu-statement-expression
CFLAGS += -Wno-gnu-compound-literal-initializer -Wno-gnu-zero-variadic-macro-arguments
CFLAGS += -Ilib/cglm/include -Ilib/glad/include -Ilib/glfw/include -Ilib/stb -Ilib/noise -lrt # -fbracket-depth=1024
LDFLAGS = lib/glad/src/glad.o lib/cglm/libcglm.a lib/glfw/src/libglfw3.a lib/noise/libnoise.a -lm
# GLFW required frameworks on OSX
ifeq ($(UNAME_S), Darwin)
LDFLAGS += -framework OpenGL -framework IOKit -framework CoreVideo -framework Cocoa
endif
ifeq ($(UNAME_S), Linux)
LDFLAGS += -ldl -lpthread
endif
SRC = $(wildcard src/**/*.c) $(wildcard src/*.c) $(wildcard src/**/**/*.c) $(wildcard src/**/**/**/*.c)
OBJ = $(SRC:.c=.o)
BIN = bin
.PHONY: all clean
all: dirs libs game
libs:
cd lib/cglm && cmake . -DCGLM_STATIC=ON -G "MSYS Makefiles" -DCMAKE_C_COMPILER=C:/msys64/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/msys64/mingw64/bin/g++.exe && make
cd lib/glad && $(CC) -o src/glad.o -Iinclude -c src/glad.c
echo GLFW
cd lib/glfw && cmake -G "MSYS Makefiles" -DCMAKE_C_COMPILER=C:/msys64/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/msys64/mingw64/bin/g++.exe . && make
cd lib/noise && make
echo noice
dirs:
mkdir -p ./$(BIN)
run: all
$(BIN)/game
game: $(OBJ)
$(CC) -o $(BIN)/game $^ $(LDFLAGS)
%.o: %.c
$(CC) -o $# -c $< $(CFLAGS)
clean:
rm -rf $(BIN) $(OBJ)
this is the modified time.h file
#ifndef TIME_H
#define TIME_H
#define HAVE_STRUCT_TIMESPEC
#define _POSIX_C_SOURCE 199309L
#include <time.h>
#include <stdio.h>
#define TIME_UTC time(NULL)
#define NS_PER_SECOND (1000000000)
#define NS_PER_MS (1000000)
int NOW(){
struct timespec ts;
timespec_get(&ts, TIME_UTC);
return ((ts.tv_sec * NS_PER_SECOND) + ts.tv_nsec);
}
#endif
Enviorment:
get windows 10
install msys2
install boost from the zip onto the C++ include(not related but, just a heads up)
run the mingw64 shell
git clone the included link
edit the time.h in the src/util with the code
edit the Makefile with the posted one
I try to write a makefile to create an executable .mexa64 file. I have to use the gcc compiler. My current working folder looks like this:
FFTW_build.c
FFTW_func.c
Makefile.c
obj (Folder, here are my object files *.o which are created)
Source code FFTW_build.c:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
FFTW_perform();
return;
}
Source code FFTW_func.c:
#include <math.h>
#include <stdio.h>
#include <complex.h>
#include <fftw3.h>
#include "mex.h"
void FFTW_perform() {
int i;
int Npoints=10;
fftw_complex *in, *out;
fftw_plan plan;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*Npoints);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*Npoints);
plan = fftw_plan_dft_1d(Npoints, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
mexPrintf("\nCoefficcients of the expansion:\n\n");
for(i = 0; i < Npoints; i++)
{
in[i] = (i+1)+(3*i-1)*I;
mexPrintf("%d %11.7f %11.7f\n", i, creal(in[i]), cimag(in[i]));
}
mexPrintf("\n");
fftw_execute(plan);
mexPrintf("Output:\n\n");
for(i = 0; i < Npoints; i++)
{
mexPrintf("%d %11.7f %11.7f\n", i, creal(out[i]), cimag(out[i]));
}
}
Source code for Makefile.c:
################## Compiler ##################
CXX = gcc
####################################################
################## MEXSUFFIX ################
MEXSUFFIX = mexa64
####################################################
################## Home of my matlab version #####
MATLABHOME = /home/tuebel/matlab
####################################################
################## Object_File_Declaration_Folder ################
OBJS_MEX = FFTW_build.o
OBJS_FFTW_FUNC = FFTW_func.o
ODIR=obj
_OBJ = $(OBJS_MEX) $(OBJS_FFTW_FUNC)
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
####################################################
################## Header_Files ################
# Header for mex
DIR_MEX_HEADER = /home/tuebel/matlab/extern/include
_DEPS_MEX = mex.h
DEPS_MEX = $(patsubst %,$(DIR_MEX_HEADER)/%,$(_DEPS_MEX))
# Header for fftw3
DIR_FFTW_HEADER = /usr/local/include
_DEPS_FFTW = fftw3.h
DEPS_FFTW = $(patsubst %,$(DIR_FFTW_HEADER)/%,$(_DEPS_FFTW))
####################################################
################## Library_Files ################
# Libraries for mex
MEX_LIB = /home/tuebel/matlab/bin/glnxa64/libmex.so
# Libraries for FFTW
FFTW_LIB = /usr/local/lib/libfftw3.a
# Libraries for math_function
MATH_LIB = -lm
####################################################
################## Flags ################
# MEXFLAGS = -shared -Wl,--no-undefined -Wl,-rpath-link,$(MATLABHOME)/bin/glnxa64 -L$(MATLABHOME)/bin/glnxa64 -lmex -lmat -lmx -lm
MEXFLAGS = -shared -Wl,-rpath-link,$(MATLABHOME)/bin/glnxa64 -L$(MATLABHOME)/bin/glnxa64 -lmex -lmat -lmx -lm
COMPILERFLAGS = -fPIC -pthread -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fno-omit-frame-pointer -O3 -DNDEBUG
FFTW_FLAGS_INCLUDE = -I$(DIR_FFTW_HEADER)
MEX_FLAGS_INCLUDE = -I$(DIR_MEX_HEADER)
####################################################
#################### Final_Part ######################
TARGET = FFTW_MEX
all: $(TARGET)
echo ALL DONE
clean:
rm -f $(ODIR)/*.o
rm -f $(TARGET).mexa64
echo CLEAN DONE
$(ODIR)/%.o: %.c $(DEPS_MEX) $(DEPS_FFTW)
$(CXX) -c -o $# $< $(COMPILERFLAGS) $(MEX_FLAGS_INCLUDE) $(FFTW_FLAGS_INCLUDE)
# Final_Linking
$(TARGET) : $(OBJ) $(MATH_LIB) $(FFTW_LIB)
$(CXX) -o $#.$(MEXSUFFIX) $(MEX_FLAGS_INCLUDE) $(FFTW_FLAGS_INCLUDE) $^ $(MEXFLAGS)
####################################################
####################################################
####################################################
The idea is to make a FFTW using fftw3. The code works fine in the command window, but if I try to make it executable from matlab (.mexa64 file) it is not working. I get the following error message using make:
gcc -c -o obj/FFTW_build.o FFTW_build.c -fPIC -pthread -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fno-omit-frame-pointer -O3 -DNDEBUG -I/home/tuebel/matlab/extern/include -I/usr/local/include
gcc -c -o obj/FFTW_func.o FFTW_func.c -fPIC -pthread -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fno-omit-frame-pointer -O3 -DNDEBUG -I/home/tuebel/matlab/extern/include -I/usr/local/include
gcc -o FFTW_MEX.mexa64 -I/home/tuebel/matlab/extern/include -I/usr/local/include obj/FFTW_build.o obj/FFTW_func.o /usr/lib64/libm.so /usr/local/lib/libfftw3.a -shared -Wl,-rpath-link,/home/tuebel/matlab/bin/glnxa64 -L/home/tuebel/matlab/bin/glnxa64 -lmex -lmat -lmx -lm
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: /usr/local/lib/libfftw3.a(lt4-problem.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libfftw3.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:92: recipe for target 'FFTW_MEX' failed
make: *** [FFTW_MEX] Error 1
Can someone help me out? This is my first Makefile and I would be glad for any help... I am also glad for corrections to the Makefile...
Thanks a lot!
It is a bit unclear what you mean by an "executable" .mexa64 file.
MATLAB's mex compiler will let you compile C/C++ code with MATLAB libraries into a mex file (with 64 bit architecture for you here) that you can then "execute" via MATLAB's command line. This seems to be what you have gotten to work already.
However, if you want to have a stand alone "executable" outside of MATLAB, you need to work with MATLAB's mcr compiler (see the reference here). There are flags that you can set in the process to be build an object file which you can then link with later on with your makefile as you are trying to now.
So, don't mix mex compiled files which are runnable within MATLAB and mcr compiled code that is executable outside of it.
Apart from this, gcc is complaining that there is no main() function. I don't see one in your code here either, but you need a main() function for a standalone executable.
I am in the process of converting my gmake build to cmake builds. The application builds fine with gmake, but I get the errors below when I use cmake.
Below are the gmake and cmake files.
parent Makefile
CC := gcc
CFLAGS := -g -w -m32
INC_DIR := ../includes
OBJ_DIR := ../objects
BIN_DIR := ../bin
child Makefile
include ../../Makefile
SHR_FX := ../$(OBJ_DIR)/shrfx.o
SHRXML := ../$(OBJ_DIR)/shrxml.o
TMP_BIN_DIR = ../$(BIN_DIR)
TMP_INC_DIR = ../$(INC_DIR)
EXECUTABLES := common flogmon
all: $(EXECUTABLES)
%: %.c OAhelper.c OAhelper.h $(SHR_FX) $(TMP_INC_DIR)
#-rm -f $# ## QUIET (#). CONTINUE IF FILE NOT FOUND (-)
$(CC) $(CFLAGS) -I $(TMP_INC_DIR) $(LDLIBPATHFLAGS) -o $# $#.c OAhelper.c $(SHR_FX)
#-chmod 0775 $# #SH(#),CONT(-). Allow others to do it.
mv $# $(TMP_BIN_DIR)
parent CMakeList.txt
cmake_minimum_required(VERSION 2.8.9)
project(program)
set(CMAKE_BUILD_TYPE Release)
set (EXECUTABLE_OUTPUT_PATH "/home/user/workspace/program")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -w -m32")
add_subdirectory(opaid/opaid_helper)
child CMakeList.txt
cmake_minimum_required(VERSION 2.8.9)
#Bring the headers
include_directories(../../includes)
set (PROJ_LIST "common;flogmon")
message ( STATUS "CFLAGS : " ${CMAKE_C_FLAGS})
foreach (PROJ ${PROJ_LIST})
project(${PROJ})
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath=${EXECUTABLE_OUTPUT_PATH}:${EXECUTABLE_OUTPUT_PATH}../RSA/cryptocme3001/library/lib")
add_executable(${PROJ} ${PROJ}.c OAhelper.c )
target_link_libraries(${PROJ} LINK_PUBLIC shrfx)
install(TARGETS ${PROJ} DESTINATION ${EXECUTABLE_OUTPUT_PATH})
endforeach()
Error
Building C object /CMakeFiles/common.dir/common.c.o
In file included from /usr/include/features.h:375:0,
from /usr/include/sys/poll.h:22,
from /usr/include/poll.h:1,
from /home/user/workspace/program/src/common.c:26:
/usr/include/sys/stat.h:503:1: error: conflicting types for ‘stat64’
__NTH (stat64 (const char *__path, struct stat64 *__statbuf))
^
In file included from
/home/user/workspace/program/src/../../includes/fxgen.h:205:0,
from /home/user/workspace/program/src/../../includes/fx.h:286,
from /home/user/workspace/program/src/common.c:39:
/usr/include/sys/stat.h:229:12: note: previous declaration of ‘stat64’
was here extern int stat64 (const char *__restrict __file,
If I look in /usr/include/sys/stat.h...
503
# if defined __USE_LARGEFILE64 \
&& (! defined __USE_FILE_OFFSET64 \
|| (defined __REDIRECT_NTH && defined __OPTIMIZE__))
__extern_inline int
__NTH (stat64 (const char *__path, struct stat64 *__statbuf))
{
return __xstat64 (_STAT_VER, __path, __statbuf);
}
229
#ifdef __USE_LARGEFILE64
extern int stat64 (const char *__restrict __file,
struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2));
extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
#endif
Adding this to my CMAKEList.txt solved the problem:
STRING(REPLACE "-O3" "-O0" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
I am trying to set up the fastHOG codebase in my linux server, but unable to finish it as i am getting heap of link errors. I am giving here a sample portion of the link errors
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0x910): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0x944): undefined reference to 'cudaGetErrorString'
/home/n8385106/bin/contrib/qut/qutanomaly/matlab/person- detector/fasthog/obj/release/HOG/HOGHistogram.cu.o: In function 'InitHistograms(int, int, int, int, int, float)':
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xac0): undefined reference to 'cudaCreateChannelDesc'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xafe): undefined reference to 'cudaMallocArray'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xb46): undefined reference to 'cudaMemcpyToArray'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xc3d): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xc63): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xc89): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xcae): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xccd): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd01): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd15): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd29): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd3d): undefined reference to 'cudaGetErrorString'
It seems the linker didn't realize any of the linker libraries provided in the make file. It did not say anything like "was unable to find this library" but it avoided all the information provided about the libraries to be linked such as
# Libs
LIB := -L$(CUDA_INSTALL_PATH)/cuda/lib64 -L$(LIBDIR) - L$(COMMONDIR)/lib/$(OSLOWER)
# If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
ifeq ($(USECUDADYNLIB),1)
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
# static linking, we will statically link against CUDA and CUDART
ifeq ($(USEDRVAPI),1)
LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
LIB += -lcudart ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
endif
endif
ifeq ($(USECUFFT),1)
ifeq ($(emu),1)
LIB += -lcufftemu
else
LIB += -lcufft
endif
endif
ifeq ($(USECUBLAS),1)
ifeq ($(emu),1)
LIB += -lcublasemu
else
LIB += -lcublas
endif
endif
I was able to create all the object files but problem is comming during the linking process, I am a newbie to CUDA, Can anyone please help me to sort this out?
My OS is 64 bit linux
Edited : My MakeFile
# Add source files here
EXECUTABLE := fastHOG
# C/C++ source files (compiled with gcc / c++)
CCFILES := \
fastHOG.cpp \
# HOG UTILS
CCUTILS := \
ImageWindow.cpp \
# CC HOG
CCHOG := \
HOGImage.cpp \
HOGEngine.cpp \
HOGNMS.cpp \
# CUDA HOG
CUFILES := \
HOGEngineDevice.cu \
HOGConvolution.cu \
HOGHistogram.cu \
HOGPadding.cu \
HOGScale.cu \
HOGSVMSlider.cu \
HOGUtils.cu \
################################################################################
# Rules and targets
include common.mk
Contents of the common.mk file
################################################################################
#
# Copyright 1993-2006 NVIDIA Corporation. All rights reserved.
#
################################################################################
#
# Common build script
#
################################################################################
.SUFFIXES : .cu .cu_dbg.o .c_dbg.o .cpp_dbg.o .cu_rel.o .c_rel.o .cpp_rel.o .cubin
#Add new SM Versions here as devices with new Compute Capability are released
SM_VERSIONS := sm_10 sm_11 sm_12 sm_13
CUDA_INSTALL_PATH ?= fasthoglib/cuda/cuda
ifdef cuda-install
CUDA_INSTALL_PATH := $(cuda-install)
endif
# detect OS
OSUPPER = $(shell uname -s 2>/dev/null | tr [:lower:] [:upper:])
OSLOWER = $(shell uname -s 2>/dev/null | tr [:upper:] [:lower:])
# 'linux' is output for Linux system, 'darwin' for OS X
DARWIN = $(strip $(findstring DARWIN, $(OSUPPER)))
# Basic directory setup for SDK
# (override directories only if they are not already defined)
SRCDIR ?=
SRCDIRUTILS ?= Utils
SRCDIRHOG ?= HOG
ROOTDIR ?= /home/n8385106/src/saivt-vxl/contrib/qut/qutanomaly/matlab/pedestrian-detector/fasthoglib/cuda/sdk
ROOTBINDIR ?= /home/n8385106/bin/contrib/qut/qutanomaly/matlab/person-detector/fasthog/bin
BINDIR ?= $(ROOTBINDIR)
ROOTOBJDIR ?= /home/n8385106/bin/contrib/qut/qutanomaly/matlab/person-detector/fasthog/obj
LIBDIR := $(ROOTDIR)/C/lib
COMMONDIR := $(ROOTDIR)/C/common
# Compilers
NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc
CXX := g++
CC := gcc
LINK := g++ -fPIC
# Includes
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/cuda/include -I$(COMMONDIR)/inc
# architecture flag for cubin build
CUBIN_ARCH_FLAG := -m32
# Warning flags
CXXWARN_FLAGS := \
-W -Wall \
-Wimplicit \
-Wswitch \
-Wformat \
-Wchar-subscripts \
-Wparentheses \
-Wmultichar \
-Wtrigraphs \
-Wpointer-arith \
-Wcast-align \
-Wreturn-type \
-Wno-unused-function \
$(SPACE)
CWARN_FLAGS := $(CXXWARN_FLAGS) \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wnested-externs \
-Wmain \
# Compiler-specific flags
NVCCFLAGS :=
CXXFLAGS := $(CXXWARN_FLAGS)
CFLAGS := $(CWARN_FLAGS)
# Common flags
COMMONFLAGS += $(INCLUDES) -DUNIX
# Debug/release configuration
ifeq ($(dbg),1)
COMMONFLAGS += -g
NVCCFLAGS += -D_DEBUG
BINSUBDIR := debug
LIBSUFFIX := D
else
COMMONFLAGS += -O3
BINSUBDIR := release
LIBSUFFIX :=
NVCCFLAGS += --compiler-options -fno-strict-aliasing
CXXFLAGS += -fno-strict-aliasing
CFLAGS += -fno-strict-aliasing
endif
# append optional arch/SM version flags (such as -arch sm_11)
#NVCCFLAGS += $(SMVERSIONFLAGS)
# architecture flag for cubin build
CUBIN_ARCH_FLAG := -m32
# detect if 32 bit or 64 bit system
HP_64 = $(shell uname -m | grep 64)
# OpenGL is used or not (if it is used, then it is necessary to include GLEW)
ifeq ($(USEGLLIB),1)
ifneq ($(DARWIN),)
OPENGLLIB := -L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL -lGLU $(COMMONDIR)/lib/$(OSLOWER)/libGLEW.a
else
OPENGLLIB := -lGL -lGLU -lX11 -lXi -lXmu
ifeq "$(strip $(HP_64))" ""
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
endif
endif
CUBIN_ARCH_FLAG := -m64
endif
ifeq ($(USEGLUT),1)
ifneq ($(DARWIN),)
OPENGLLIB += -framework GLUT
else
OPENGLLIB += -lglut
endif
endif
ifeq ($(USEPARAMGL),1)
PARAMGLLIB := -lparamgl$(LIBSUFFIX)
endif
ifeq ($(USERENDERCHECKGL),1)
RENDERCHECKGLLIB := -lrendercheckgl$(LIBSUFFIX)
endif
USECUDPP := 1;
ifeq ($(USECUDPP), 1)
ifeq "$(strip $(HP_64))" ""
CUDPPLIB := -lcudpp
else
CUDPPLIB := -lcudpp64
endif
CUDPPLIB := $(CUDPPLIB)$(LIBSUFFIX)
ifeq ($(emu), 1)
CUDPPLIB := $(CUDPPLIB)_emu
endif
endif
# Libs
LIB := -L$(CUDA_INSTALL_PATH)/cuda/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER)
# If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
ifeq ($(USECUDADYNLIB),1)
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
# static linking, we will statically link against CUDA and CUDART
ifeq ($(USEDRVAPI),1)
LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
LIB += -lcudart ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
endif
endif
ifeq ($(USECUFFT),1)
ifeq ($(emu),1)
LIB += -lcufftemu
else
LIB += -lcufft
endif
endif
ifeq ($(USECUBLAS),1)
ifeq ($(emu),1)
LIB += -lcublasemu
else
LIB += -lcublas
endif
endif
# Lib/exe configuration
ifneq ($(STATIC_LIB),)
TARGETDIR := $(LIBDIR)
TARGET := $(subst .a,$(LIBSUFFIX).a,$(LIBDIR)/$(STATIC_LIB))
LINKLINE = ar rucv $(TARGET) $(OBJS)
else
LIB += -lcutil$(LIBSUFFIX)
# Device emulation configuration
ifeq ($(emu), 1)
NVCCFLAGS += -deviceemu
CUDACCFLAGS +=
BINSUBDIR := emu$(BINSUBDIR)
# consistency, makes developing easier
CXXFLAGS += -D__DEVICE_EMULATION__
CFLAGS += -D__DEVICE_EMULATION__
endif
TARGETDIR := $(BINDIR)/$(BINSUBDIR)
TARGET := $(TARGETDIR)/$(EXECUTABLE)
#fltk
LIB += -lfltk2 -lXft -lfltk2_images -lXext -lXinerama -lXi
#boost thread for interface
LIB += -lboost_thread
#read images in HOGImage from file
LIB := /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a
LINKLINE = $(LINK) -o $(TARGET) $(OBJS) $(LIB)
endif
# check if verbose
ifeq ($(verbose), 1)
VERBOSE :=
else
VERBOSE := #
endif
################################################################################
# Check for input flags and set compiler flags appropriately
################################################################################
ifeq ($(fastmath), 1)
NVCCFLAGS += -use_fast_math
endif
ifeq ($(keep), 1)
NVCCFLAGS += -keep
NVCC_KEEP_CLEAN := *.i* *.cubin *.cu.c *.cudafe* *.fatbin.c *.ptx
endif
ifdef maxregisters
NVCCFLAGS += -maxrregcount $(maxregisters)
endif
# Add cudacc flags
NVCCFLAGS += $(CUDACCFLAGS)
# workaround for mac os x cuda 1.1 compiler issues
ifneq ($(DARWIN),)
NVCCFLAGS += --host-compilation C
endif
# Add common flags
NVCCFLAGS += $(COMMONFLAGS)
CXXFLAGS += $(COMMONFLAGS)
CFLAGS += $(COMMONFLAGS)
ifeq ($(nvcc_warn_verbose),1)
NVCCFLAGS += $(addprefix --compiler-options ,$(CXXWARN_FLAGS))
NVCCFLAGS += --compiler-options -fno-strict-aliasing
endif
################################################################################
# Set up object files
################################################################################
OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CCFILES)))
OBJDIRUTILS := $(ROOTOBJDIR)/$(BINSUBDIR)/$(SRCDIRUTILS)
OBJS += $(patsubst %.cpp,$(OBJDIRUTILS)/%.cpp.o,$(notdir $(CCUTILS)))
OBJDIRHOG := $(ROOTOBJDIR)/$(BINSUBDIR)/$(SRCDIRHOG)
OBJS += $(patsubst %.cu,$(OBJDIRHOG)/%.cu.o,$(notdir $(CUFILES)))
OBJS += $(patsubst %.cpp,$(OBJDIRHOG)/%.cpp.o,$(notdir $(CCHOG)))
################################################################################
# Set up cubin files
################################################################################
CUBINDIR := $(SRCDIR)data
CUBINS += $(patsubst %.cu,$(CUBINDIR)/%.cubin,$(notdir $(CUBINFILES)))
################################################################################
# Rules
################################################################################
$(OBJDIR)/%.c.o : $(SRCDIR)%.c $(C_DEPS)
$(VERBOSE)$(CC) $(CFLAGS) -o $# -c $<
$(OBJDIRUTILS)/%.cpp.o : $(SRCDIRUTILS)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
$(OBJDIR)/%.cpp.o : $(SRCDIR)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
$(OBJDIRHOG)/%.cpp.o : $(SRCDIRHOG)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
$(OBJDIR)/%.cu.o : $(SRCDIR)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -c $<
$(OBJDIRHOG)/%.cu.o : $(SRCDIRHOG)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -c $<
$(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory
$(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -cubin $<
#
# The following definition is a template that gets instantiated for each SM
# version (sm_10, sm_13, etc.) stored in SMVERSIONS. It does 2 things:
# 1. It adds to OBJS a .cu_sm_XX.o for each .cu file it finds in CUFILES_sm_XX.
# 2. It generates a rule for building .cu_sm_XX.o files from the corresponding
# .cu file.
#
# The intended use for this is to allow Makefiles that use common.mk to compile
# files to different Compute Capability targets (aka SM arch version). To do
# so, in the Makefile, list files for each SM arch separately, like so:
#
# CUFILES_sm_10 := mycudakernel_sm10.cu app.cu
# CUFILES_sm_12 := anothercudakernel_sm12.cu
#
define SMVERSION_template
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1).o,$(notdir $(CUFILES_$(1))))
$(OBJDIR)/%.cu_$(1).o : $(SRCDIR)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) -o $$# -c $$< $(NVCCFLAGS) -arch $(1)
endef
# This line invokes the above template for each arch version stored in
# SM_VERSIONS. The call function invokes the template, and the eval
# function interprets it as make commands.
$(foreach smver,$(SM_VERSIONS),$(eval $(call SMVERSION_template,$(smver))))
$(TARGET): makedirectories $(OBJS) $(CUBINS) Makefile
$(VERBOSE)$(LINKLINE)
cubindirectory:
$(VERBOSE)mkdir -p $(CUBINDIR)
makedirectories:
$(VERBOSE)mkdir -p $(LIBDIR)
$(VERBOSE)mkdir -p $(OBJDIR)
$(VERBOSE)mkdir -p $(OBJDIRUTILS)
$(VERBOSE)mkdir -p $(OBJDIRHOG)
$(VERBOSE)mkdir -p $(TARGETDIR)
tidy :-lboost_thread
$(VERBOSE)find . | egrep "#" | xargs rm -f
$(VERBOSE)find . | egrep "\~" | xargs rm -f
clean : tidy
$(VERBOSE)rm -f $(OBJS)
$(VERBOSE)rm -f $(CUBINS)
$(VERBOSE)rm -f $(TARGET)
$(VERBOSE)rm -f $(NVCC_KEEP_CLEAN)
clobber : clean
$(VERBOSE)rm -rf $(ROOTOBJDIR)
The common.mk has been broken (presumably by a modification you made to it) here:
LIB := /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a
This is undoubtedly not what you want, it is destroying all of the carefully crafted library dependencies assigned above it. I guess you intended something like
LIB += /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a