question

Stefan Haeussler avatar image
1 Like"
Stefan Haeussler asked Phil BoBo edited

Include c++ header files in Flexsim 7.7

Hi all,

I am trying to include a C++ header file in my flexsim 7.7.

I followed the instructions of the Forum: (https://www.flexsim.com/community/forum/showthread.php?t=3358): I created a node with string data within the Tools folder in the tree, right-clicked it and selected Build > Toggle Node as Global C++, then put

#include "../../../libraries/Lingd16.h"

within that node's data, but Flexsim keeps saying:

all.obj : error LNK2019: unresolved external symbol LScreateEnvLng referenced in function ObjectFunction376__project_model_Tools_UserCommands_command2_code

all.obj : error LNK2019: unresolved external symbol LSdeleteEnvLng referenced in function ObjectFunction376__project_model_Tools_UserCommands_command2_code

.\A\flexsimcontent.dll : fatal error LNK1120: 4 unresolved externals

When I build the solution in Visual Studio Express 2015 it says no errors - any ideas?

Yours,

Stefan

FlexSim 7.7.4
c++
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Stefan Haeussler avatar image
3 Likes"
Stefan Haeussler answered Phil BoBo edited

Dear all,

I found a solution to my problem by creatng a DLL that attaches to FlexSim. Now I am calling the function specified in the dll through a User Command.

The manual really helped a lot: Creating DLLs that attach to FlexSim

Additionally, I added the .lib file of (Lingd64_16.lib) the additional dependencies in Visual Studio-Properties. (Properties - Configuration Properties - Linker - Input - Additional dependencies)

Thanks again for your help,

Greetings, Stefan

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Phil BoBo avatar image
5 Likes"
Phil BoBo answered Stefan Haeussler edited

Additional Binaries

You can use the ModelLibraries functionality to specify additional lib or obj files that contain the compiled C++ code that is declared in the header file you are including.

From User Manual ModelLibraries Node:

binaries - You can add a node named "binaries" and give it text data that specifies a list of additional .lib or .obj files that you want to link to when FlexSim is compiled. This is only needed if you have c++ toggled code that must be compiled, or if you expect your end users to define c++ code that can access pre-compiled functionality. This text will be added to the "Additional Library Dependency" field during the C++ linker phase. The linker's library path is specified as /program/system/lib in FlexSim's install directory, so to link with a lib file in FlexSim's libraries directory, you would specify a path like: ../../../libraries/MyLib...

Using a DLL Instead

An easier way to include additional C++ library code would be to create a DLL that attached to FlexSim and includes the custom library you are trying to use. The link below explains how to create DLLs that attach to FlexSim.

Creating DLLs that attach to FlexSim

· 6
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Stefan Haeussler avatar image Stefan Haeussler commented ·

Thanks to both of you - I tried both suggestions, but I keep getting the same errors. Here is a screenshot of my tree:

I also tried to change the rank of the "Globalcode" to Rank 1, but nothing changed.

Thanks again for your suggestions,

Greetings,

Stefan

0 Likes 0 ·
screenshot2.jpg (20.1 KiB)
Brandon Peterson avatar image Brandon Peterson ♦ commented ·

In the model that I was working on a few years ago. I placed my .lib files in the "\program\system\lib" directory inside of the Flexsim install directory. That way I just had to list only the file name in the binaries node. You can try that and see if that works for you as well.

0 Likes 0 ·
Stefan Haeussler avatar image Stefan Haeussler commented ·

Unfortunately that did not solve the problem either...

How did you name your "Global Code"-Node? Maybe I need to call it differently (not Globalcode)?

Additionally, I looked at the "flexbinaries.txt" textfile which Flexsim creates when it compiles the code:

The Lingd64_16.lib is not in the list:

Thanks again,

Stefan

0 Likes 0 ·
flexbinaries.jpg (26.4 KiB)
Brandon Peterson avatar image Brandon Peterson ♦ Stefan Haeussler commented ·

Don't worry about the "flexbinaries.txt" file because it is not created during the compile. It is installed with Flexsim and isn't changed afterwards.

I noticed that the path to your .lib file begins with "..\..\libraries" but the path in the example from Phil is "..\..\..\libraries". You can try fixing this first.

If that didn't work then when you put the .lib file in the Flexsim install directory "\program\system\lib" did you change the text in your binaries node to just the name of the file (Lingd64_16.lib)? If not, then try that.

If that didn't work then try using an absolute path to the lib file in the binaries node text. Make sure you put quotes around it if there are any spaces.

0 Likes 0 ·
Stefan Haeussler avatar image Stefan Haeussler Brandon Peterson ♦ commented ·

I tried it with "..\..\..\libraries" as well :-)

I'll try changing the text to "just the name" and report whether it solved the problem on Monday.

Thanks again for you support and have a nice weekend!

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.