You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否将MAVLink C库转为DLL及用Eclipse生成.so以在myRio1900的Linux RT调用?

Hey Alex, let's break down your two MAVLink library questions one by one—both are totally doable with the right steps, so let's dive in:

Here's a straightforward workflow to turn your MAVLink C code into a usable DLL:

  • Step 1: Prepare your MAVLink code
    First, ensure you have the full set of MAVLink C files generated (use the official MAVLink generator to pick your target protocol/vehicle and export the C library). Gather all relevant .c and .h files for your use case.
  • Step 2: Set up a DLL project in Visual Studio
    Open Visual Studio, create a new Dynamic-link Library (DLL) project. Add all your MAVLink .c files to the project, and configure the include directories to point to your MAVLink header files.
  • Step 3: Export functions for external access
    DLLs require explicit function exports so other programs can call them. Choose one of these two methods:
    • Use the __declspec(dllexport) attribute: Add this macro to your main MAVLink header:
      #ifdef MAVLINK_EXPORTS
      #define MAVLINK_API __declspec(dllexport)
      #else
      #define MAVLINK_API __declspec(dllimport)
      #endif
      
      Prepend MAVLINK_API to every function you need to expose (e.g., MAVLINK_API void mavlink_send_message(mavlink_channel_t chan, const mavlink_message_t* msg);).
    • Use a .def file: Create a mavlink.def text file in your project, list exported functions under the EXPORTS section:
      EXPORTS
      mavlink_send_message
      mavlink_parse_char
      // Add other required functions here
      
  • Step 4: Compile the DLL
    Build your project—Visual Studio will generate a .dll file (in the Debug/Release output folder) and a corresponding .lib import library. Use the .lib when linking your application to the DLL, and keep the .dll in the same directory as your executable at runtime.
2. Creating a .so Library for myRio1900 Linux RT Using Eclipse

The myRio1900 runs an ARM-based NI Linux RT system, so you'll need cross-compilation tools. Here's how to set this up in Eclipse:

  • Step 1: Prepare Eclipse and cross-compiler
    Install Eclipse CDT (C/C++ Development Tools) if you don't have it. Then install the NI myRio Toolkit—it includes the arm-linux-gnueabihf-gcc cross-compiler tailored for the myRio's architecture.
  • Step 2: Import your MAVLink project
    Create a new C project in Eclipse, select Empty Project, and choose the Cross GCC toolchain. Add all your MAVLink .c files to the project, and configure include paths to point to your MAVLink headers.
  • Step 3: Add compiler flags for shared libraries
    Shared libraries require position-independent code. Go to Project Properties > C/C++ Build > Settings > GCC C Compiler > Miscellaneous and add -fPIC to the "Other flags" field.
  • Step 4: Configure linker to generate .so
    In the linker settings (Project Properties > C/C++ Build > Settings > GCC C Linker > Shared Library Settings), check the "Shared" checkbox (this adds the -shared flag). You can also set the output library name (e.g., libmavlink.so).
  • Step 5: Compile and deploy to myRio1900
    Build the project to generate the .so file. Transfer it to your myRio1900 using SSH/SCP, or NI's built-in file transfer tools. Place it in a system-accessible directory like /usr/lib or add its path to the LD_LIBRARY_PATH environment variable.
  • Step 6: Link against the library
    When compiling your myRio application (either cross-compiling or on-device), use -lmavlink to link against the library, and -L/path/to/your/library to specify its location.

内容的提问来源于stack exchange,提问作者Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:21:56