[Since this is off-topic, I'm happy to take this off-list of mods deem it 
necessary].

While, "yes" adding the directory containing the DLL to the PATH env var is 
one way the Windows dynamic loading can find a DLL.
Dynamic-link library search order - Win32 apps | Microsoft Learn 
<https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-unpackaged-apps>

I feel like you might not be aware of - or not considering - how 
environments in processes work. There is the question of how you updated 
the PATH variable, i.e., it depends on the process where you updated the 
environment (e.g., an existing instance of Powershell, the login instance 
of explorer.exe, or somewhere else) and whether or not Matlab was running 
and restarted.

Although you've updated the PATH, could it have been while Matlab was 
running and has not been restarted? Or, you may have updated the PATH in a 
running cmd.exe shell with a simple PATH=..., or in a running Powershell 
instance with $env:PATH=... Starting a new copy of Matlab from the Start 
Menu where the explorer.exe is unaware of the change made will inherit an 
environment from explorer.exe that does not contain your change. Maybe the 
PATH was updated through Control Panel or Settings.app but Matlab was 
running at the time and has its own copy of the environment. 

Environment Variables - Win32 apps | Microsoft Learn 
<https://learn.microsoft.com/en-us/windows/win32/procthread/environment-variables>

User Environment Variables - Win32 apps | Microsoft Learn 
<https://learn.microsoft.com/en-us/windows/win32/shell/user-environment-variables>



On Saturday, February 1, 2025 at 1:31:02 AM UTC-8 Ádám Boronyák wrote:

> Hi,
>
> Thanks for your explanations. I only add the path to the protobuf dll to 
> the PATH environment variable. I read that it should be enough for Matlab 
> to find the dll.
> Michael Ngarimu what do you mean by "correctly provide the protobuf DLL to 
> Matlab"? How did you do it?
>
> Regards,
> Adam
>
> Michael Ngarimu a következőt írta (2025. február 1., szombat, 3:40:40 
> UTC+1):
>
>> This does not look like a protobuf issue to me. Is it possible this is 
>> simply an issue that you haven't told Matlab how to find the protobuf DLL? 
>>
>> Where is the "could not find dll like" issue?
>>
>> Beyond the scope of this list, I have ,
>> 1. used vcpkg to acquire protobuf 3.21.12,
>> 2. taken your model and modified the LIB_PATH and INC_PATH to point to 
>> location where vcpkg installed the protobuf headers and built libs,
>> 3. rebuilt your s-function
>>
>> The only issue I ran into is Matlab S-Function builder gave a vague error 
>> that it could not obtain sizes from the MEX file.... 
>>
>> but that was because the MEX failed to build completely... 
>>
>> but that was because Matlab doesn't know where to find the protobuf DLL. 
>>
>> How are you making the protobuf DLL available to Matlab?
>>
>> When I correctly provide the protobuf DLL to Matlab, I can see the value 
>> you assign and retrieve through the protobuf::Timestamp (the value, 2) in 
>> the outputs from your model.
>> [image: Screenshot 2025-01-31 183750.png]
>>
>> On Friday, January 31, 2025 at 1:14:14 AM UTC-8 Ádám Boronyák wrote:
>>
>>> Hi,
>>>
>>> I would like to integrate and use protobuf C++ library in Simulink 
>>> S-functions on Windows 10. For this purpose I have installed protobuf 
>>> 3.21.12 using Visual Studio 2022 via vcpkg. I have created a simple 
>>> Simulink model (attached to the email) with an S-function builder. In this 
>>> S-function builder I set a library path to vcpkg lib folder and an include 
>>> path to vcpkg include folder to be able to find protobuf headers and 
>>> libraries. I set there also the libprotobuf.lib as an entry. In environment 
>>> variables I set path to the vcpkg bin folder because libprotobuf.lib links 
>>> to the corresponding dll file. So every link and entry have been set for 
>>> the project.
>>> In my S-function in wrapper.cpp file (attached to the email), I create 
>>> an instance of the built-in Timestamp message, set the seconds field to 2 
>>> and give it to the output of the S-function. After I compile the S-function 
>>> or try to run the Simulink model, Simulink freezes and after some time I 
>>> get a "could not find a dll" like issue which does not help to debug the 
>>> issue.
>>> I created a contact with Mathworks and they suggested a way to debug 
>>> this. So I opened Visual Studio, opened the wrapper file, set a break point 
>>> to the instance creation and attached the Matlab process to it. After I try 
>>> to run my Simulink model I get an access violation exception. I have 
>>> attached a screenshot about it.
>>> Mathworks suggested that I should contact you to help troubleshooting 
>>> this issue. What is your opinion about it? What can cause this issue?
>>>
>>> Regards,
>>> Adam
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/protobuf/0708dd9e-8386-4a03-b392-bacd21522d8fn%40googlegroups.com.

Reply via email to