This is our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

# Adding external lib to my own plugin

 0 Hello, I am trying to write my own wireshark v2.0.2 plugin and I need to use a custom library and xerces library (.lib files) in my dissector. I try to add this libraries in Makefile.am like this : LIBS = -L -lcustom_lib -lxerces-c_3 I also try to add libraries in Makefile.nmake like this :  CFLAGS=$(WARNINGS_ARE_ERRORS)$(STANDARD_CFLAGS) \ /I../.. $(GLIB_CFLAGS) \ /I$(PCAP_DIR)\include \ /Icustom_lib\include ... LINK_PLUGIN_WITH=....\epan\libwireshark.lib CFLAGS=$(CFLAGS) LINK_PLUGIN_WITH=$(LINK_PLUGIN_WITH) xerces-c_3.lib LINK_PLUGIN_WITH=$(LINK_PLUGIN_WITH) custom_lib.lib  But none of these solutions works for me, I have this error message when I run "msbuild" command : error LNK2019: unresolved external symbol __imp__custom_init fatal error LNK1120: 1 unresolved externals Can anyone help me please ? Thanks you. asked 23 Jan '17, 00:55 sguaiana 11●1●1●5 accept rate: 0% Your problem description is a little confusing, mixing up Makefile.am (used by autotools builds on platforms other than Windows), Makefile.nmake (deprecated and used by non-CMake builds on Windows) and msbuild, used by CMake builds on Windows. So, how are you building, using CMake and msbuild on Windows? (23 Jan '17, 03:06) grahamb ♦ Hello, yes I use CMake and msbuild on Windows (23 Jan '17, 04:04) sguaiana  1 I think you should be able to modify CMakeLists.txt in your plugin directory to add the required library to your plugin target after the target is created with the add_plugin_target() call, using target_link_libraries something like: add_plugin_library(your_plugin_name) target_link_libraries(your_plugin_name path\to\your\library)  Extra work will then be required to copy the library dll to the build directory and then add it into the packaging. answered 23 Jan '17, 05:10 grahamb ♦ 19.8k●3●30●206 accept rate: 22% Thank you for your help. I had this line in CMakeLists.txt (in my plugin folder) just after 'add_plugin_library' line so I have : add_plugin_library(myplugin) target_link_libraries(myplugin custom_lib.lib xerces-c_3.lib) When I run 'msbuild' command I have this error : LINK : fatal error LNK1181: cannot open input file 'custom_lib.lib' (23 Jan '17, 06:48) sguaiana 1 Your "answer" has been converted to a comment as that's how this site works. Please read the FAQ for more information. And where are the libraries custom_lib.lib and xerces-c_3.lib? Note that my example included the path\to\ the library. Finding libraries in CMake is somewhat complicated, e.g. see here. You can shortcut that by providing the path in the call to target_link_libraries, or by adding the link paths with a call to link_directories, or possibly by importing the library as shown in this S.O answer (23 Jan '17, 07:00) grahamb ♦ My libraries are in plugin folder "..src/plugins/myplugin/". If I build with absolute path to my libraries, msbuild works. But I want to use relative path (I think it's better). So as you advised me, I put this line before 'add_plugin_library' : link_directories(${CMAKE_CURRENT_SOURCE_DIR}) CMake and msbuild command seem to work, no error occured. When I run Wireshark, an error messages appears indicating that it could not load custom_lib and xerces-c_3. So, I put custom_lib.dll and xerces-c_3.dll in 'build\run\RelWithDebInfo' folder and error messages disappears. Thank you very much for your help ! Best regards. (23 Jan '17, 07:39) sguaiana When I run Wireshark, an error messages appears indicating that it could not load custom_lib and xerces-c_3. So, I put custom_lib.dll and xerces-c_3.dll in 'build\run\RelWithDebInfo' folder and error messages disappears. This was what I meant in part of my answer: Extra work will then be required to copy the library dll to the build directory and then add it into the packaging. You could add copy commands similar to what's done in the top-level CMakeLists.txt to copy over the 3rd party DLL's to the build directory, and to build an installer you would need to modify packaging\nsis\custom_plugins.txt If an answer has solved your issue, please accept the answer for the benefit of other users by clicking the checkmark icon next to the answer. Please read the FAQ for more information. (23 Jan '17, 07:57) grahamb ♦
 toggle preview community wiki:

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Question tags:

×21
×10
×4
×4
×4

question asked: 23 Jan '17, 00:55

question was seen: 1,549 times

last updated: 23 Jan '17, 07:57

### Related questions

p​o​w​e​r​e​d by O​S​Q​A