|
[Sponsors] |
February 23, 2024, 05:32 |
Linking Library
|
#1 |
New Member
Join Date: Aug 2022
Posts: 16
Rep Power: 3 |
Hello everyone
i am creating a library libhello.so . this library contains function called hello(int); by writing hello(100) it will print Hello world 100 times . these are the definition and header file as shown below hello.h Code:
#ifndef HELLO_H #define HELLO_H int hello(int ); #endif and my hello.c as shown below Code:
#include "hello.h" #include <stdio.h> int hello(int n){ int i; for(i=1;i<n;i++) printf("Hello world\n"); return 1; } /home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/hello so i created the .o file as gcc -c -fPIC hello.c -o /home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/hello/lib/hello.o -I/home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/hello/include then i created the libhello.so file inside the lib as gcc ./lib/hello.o -shared -o /home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/hello/lib/libhello.so Now i want to use the libhello.so with openfoam solver namely icoFoam in the icoFoam.c ... i have renamed the icoFoam.C as icoFoam_with_hello_func.C and i have added the header file #include "hello.h" and the function hello(100); to it as shown below Code:
#include "fvCFD.H" #include "pisoControl.H" #include "hello.h" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) { hello(100); argList::addNote ( "Transient solver for incompressible, laminar flow" " of Newtonian fluids." ); .... .... ... ... Code:
EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I/home/urban/OpenFOAM/OpenFOAM-1912/applications/solvers/incompressible/hello/include EXE_LIBS = \ -lfiniteVolume \ -lmeshTools \ -Wl,-rpath=/home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/hello/lib \ -L/home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/hello/lib \ -lhello Code:
icoFoam_with_hello_func.C EXE = $(FOAM_APPBIN)/icoFoam_with_hello_func.C Code:
Making dependency list for source file icoFoam_with_hello_func.C g++ -std=c++11 -m64 -DOPENFOAM=1912 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -Wno-unknown-pragmas -O3 -g -DNoRepository -ftemplate-depth-100 -I/home/urban/OpenFOAM/OpenFOAM-v1912/src/finiteVolume/lnInclude -I/home/urban/OpenFOAM/OpenFOAM-v1912/src/meshTools/lnInclude -I/home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/hello/include -IlnInclude -I. -I/home/urban/OpenFOAM/OpenFOAM-v1912/src/OpenFOAM/lnInclude -I/home/urban/OpenFOAM/OpenFOAM-v1912/src/OSspecific/POSIX/lnInclude -fPIC -c icoFoam_with_hello_func.C -o /home/urban/OpenFOAM/OpenFOAM-v1912/build/linux64GccDPInt32Opt/applications/solvers/incompressible/icoFoam_with_c_function/icoFoam_with_hello_func.o g++ -std=c++11 -m64 -DOPENFOAM=1912 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -Wno-unknown-pragmas -O3 -g -DNoRepository -ftemplate-depth-100 -I/home/urban/OpenFOAM/OpenFOAM-v1912/src/finiteVolume/lnInclude -I/home/urban/OpenFOAM/OpenFOAM-v1912/src/meshTools/lnInclude -I/home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/hello/include -IlnInclude -I. -I/home/urban/OpenFOAM/OpenFOAM-v1912/src/OpenFOAM/lnInclude -I/home/urban/OpenFOAM/OpenFOAM-v1912/src/OSspecific/POSIX/lnInclude -fPIC -Xlinker --add-needed -Xlinker --no-as-needed /home/urban/OpenFOAM/OpenFOAM-v1912/build/linux64GccDPInt32Opt/applications/solvers/incompressible/icoFoam_with_c_function/icoFoam_with_hello_func.o -L/home/urban/OpenFOAM/OpenFOAM-v1912/platforms/linux64GccDPInt32Opt/lib \ -lfiniteVolume -lmeshTools -Wl,-rpath=/home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/hello/lib -L/home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/hello/lib -lhello -lOpenFOAM -ldl \ -g -lm -o /home/urban/OpenFOAM/OpenFOAM-v1912/platforms/linux64GccDPInt32Opt/bin/icoFoam_with_hello_func.C /home/urban/OpenFOAM/OpenFOAM-v1912/build/linux64GccDPInt32Opt/applications/solvers/incompressible/icoFoam_with_c_function/icoFoam_with_hello_func.o: In function `main': /home/urban/OpenFOAM/OpenFOAM-v1912/applications/solvers/incompressible/icoFoam_with_c_function/icoFoam_with_hello_func.C:74: undefined reference to `hello(int)' collect2: error: ld returned 1 exit status make: *** [/home/urban/OpenFOAM/OpenFOAM-v1912/platforms/linux64GccDPInt32Opt/bin/icoFoam_with_hello_func.C] Error 1 can any one help me out or guide me any advice will be realy helpful thank you |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problem linking library | AlmostSurelyRob | OpenFOAM Programming & Development | 19 | March 1, 2017 09:59 |
Compiling library and linking it to a solver | criolla | OpenFOAM | 2 | July 27, 2016 03:13 |
custom code compilation error: library linking problem | nadine | OpenFOAM Programming & Development | 5 | October 10, 2014 09:58 |
Linking problems dynamic library | Van de Leur | OpenFOAM Programming & Development | 17 | August 2, 2012 10:52 |
OpenFOAM141dev linking error on IBM AIX 52 | matthias | OpenFOAM Installation | 24 | April 28, 2008 15:49 |