CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Using functions in coded function object | undefined symbol

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By mAlletto

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 23, 2020, 05:18
Default Using functions in coded function object | undefined symbol
  #1
New Member
 
Marius
Join Date: Aug 2020
Location: Germany
Posts: 11
Rep Power: 6
Muerio is on a distinguished road
Hi,

I have written a coded function object with a working code block.
Now I'm trying to package this code into individual functions so I can use them in multiple function objects and maintain a clean structure in my controlDict file.
For this I created a directory pp_functions in the system directory where I put all my header and cpp files.

I'm having problems with including and using these functions in my coded function objects.

For testing I created a header file test_methods.h
Code:
#ifndef TEST_METHODS_H// To make sure you don't declare the function more than once by including the header multiple times.
#define TEST_METHODS_H

void test_method();

#endif
and the cpp file test_methods.cpp
Code:
#include "pp_functions/test_methods.h"

void test_method()
{
    Info << "TEST METHOD" << endl;
}
in pp_functions.

My coded function object looks like this:
Code:
codedTest
{
    libs        ("libutilityFunctionObjects.so");
    type coded;
    // Name of on-the-fly generated functionObject
    name codedTest;
    codeOptions
    #{
        -I$(FOAM_CASE)/system/pp_functions
    #};
    codeInclude
    #{
        #include "test_methods.h"
    #};
    codeWrite
    #{
        test_method();
    #};
}
Running the solver results in this error message
Code:
Using dynamicCode for functionObject codedTest at line 15 in "/home/openfoam/system/controlDict/functions/codedTest"
Creating new library in "dynamicCode/codedTest/platforms/linux64GccDPInt32Opt/lib/libcodedTest_2146ab0e392c492df3767af3c8ac8b8b90ae358e.so"
Invoking "wmake -s libso /home/openfoam/dynamicCode/codedTest"
wmake libso /home/openfoam/dynamicCode/codedTest
    ln: ./lnInclude
    wmkdep: functionObjectTemplate.C
    Ctoo: functionObjectTemplate.C
    ld: /home/openfoam/dynamicCode/codedTest/../platforms/linux64GccDPInt32Opt/lib/libcodedTest_2146ab0e392c492df3767af3c8ac8b8b90ae358e.so
simpleFoam: symbol lookup error: /home/openfoam/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodedTest_2146ab0e392c492df3767af3c8ac8b8b90ae358e.so: undefined symbol: _Z11test_methodv
I'm using the docker version of OpenFoam 8.

Did I miss a step or some definition before runnning simpleFoam?
Does anyone know how to solve the "undefined symbol" error?

Any help would be appreciated.
Muerio is offline   Reply With Quote

Old   November 23, 2020, 10:20
Default
  #2
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
did you compile your cpp file. The symbol look up error is when you have defined your function (or class) but the linker did not find the actual execution block.



So you should probably compile your cpp file, make a library out of it and include it into libs. This should work




Best


Michael
olesen likes this.
mAlletto is offline   Reply With Quote

Old   November 25, 2020, 04:26
Default
  #3
New Member
 
Marius
Join Date: Aug 2020
Location: Germany
Posts: 11
Rep Power: 6
Muerio is on a distinguished road
Hi Michael,

thank you for your reply.

Quote:
Originally Posted by mAlletto View Post
So you should probably compile your cpp file, make a library out of it and include it into libs.
Obviously I didn't do that. Tried compiling it yesterday, but it always gave me errors.
I guess at this point I could just as well start to define my own function objects, that will probably be cleaner than using the coded function object with my own library of functions.
Muerio is offline   Reply With Quote

Old   November 25, 2020, 04:34
Default
  #4
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
you can include your code directly in the codeWrite or codeExecute blocks. So wmake will take care of the compilation
mAlletto is offline   Reply With Quote

Reply

Tags
coded function object


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Caffa 3D code Waliur Rahman Main CFD Forum 0 May 29, 2018 01:53
Error in compiling new drag model k.farnagh OpenFOAM Programming & Development 13 May 21, 2016 04:08
[foam-extend.org] Error compiling OpenFOAM-1.6-ext Canesin OpenFOAM Installation 137 January 20, 2016 15:56
[blockMesh] error message with modeling a cube with a hold at the center hsingtzu OpenFOAM Meshing & Mesh Conversion 2 March 14, 2012 10:56
OpenFOAM 1.6-ext git installation on Ubuntu 11.10 x64 Attesz OpenFOAM Installation 45 January 13, 2012 13:38


All times are GMT -4. The time now is 18:16.