Visual Studio 2008 C++ Windows 7 - using libusb in project

Thread Starter

syndred

Joined May 6, 2014
13
Greetings,

I have a basic issue with configuring the lastest libusb to work under Visual Studio 2008, with a Windows 7 64-bit. I installed the libusb-win32 driver for my device.

I downloaded the libusb-1.0.18-win compressed folder, and extracted it.
I then tried to create a test project.

For such purpose I followed the enclosed Readme included in folder. I decided to use static library.

I created an empty win32 console project. I created header and static folders to contain .h and .lib. I made modifications for all configurations at include directories, library directories and additional dependencies using full path for first two, then filename for additional dependency. Then, I changed to Multi-Threaded Dll for runtime thingy.

I then tried some example test code from this link (libusb.h is included in cpp code) : http://www.dreamincode.net/forums/topic/148707-introduction-to-using-libusb-10/

Then I get following error :

1>------ Build started: Project: libusbtest3, Configuration: Debug Win32 ------
1>Linking...
1>maintest.obj : error LNK2019: unresolved external symbol _libusb_exit@4 referenced in function _main
1>maintest.obj : error LNK2019: unresolved external symbol _libusb_free_device_list@8 referenced in function _main
1>maintest.obj : error LNK2019: unresolved external symbol _libusb_get_device_list@8 referenced in function _main
1>maintest.obj : error LNK2019: unresolved external symbol _libusb_set_debug@8 referenced in function _main
1>maintest.obj : error LNK2019: unresolved external symbol _libusb_init@4 referenced in function _main
1>maintest.obj : error LNK2019: unresolved external symbol _libusb_free_config_descriptor@4 referenced in function "void __cdecl printdev(struct libusb_device *)" (?
printdev@@YAXPAUlibusb_device@@@Z)
1>maintest.obj : error LNK2019: unresolved external symbol _libusb_get_config_descriptor@12 referenced in function "void __cdecl printdev(struct libusb_device *)" (?
printdev@@YAXPAUlibusb_device@@@Z)
1>maintest.obj : error LNK2019: unresolved external symbol _libusb_get_device_descriptor@8 referenced in function "void __cdecl printdev(struct libusb_device *)" (?
printdev@@YAXPAUlibusb_device@@@Z)
1>blaba\Visual Studio 2008\Projects\libusbtest3\Debug\libusbtest3.exe : fatal error LNK1120: 8 unresolved externals
1>Build log was saved at "file://blabla\Visual Studio 2008\Projects\libusbtest3\libusbtest3\Debug\BuildLog.htm"
1>libusbtest3 - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I'm assuming my library isn't recognised in project. Why is that ? I followed readme scupulously...

From what I have look up, I'm not first to have issue but I can't find sufficiently detailed explanation. Plus libusb doc is really lacking.

I post in this topic because it seems more like a general C/C++ issue, and I have little experience with linking external libraries.

Thanks in advance.
 

Attachments

ErnieM

Joined Apr 24, 2011
8,377
That error means your c files built sucessfully, but the library objects could not be found to link with the rest.

That could be one of two things (or up to 18 more things I am not aware of). If the static library has already been compiled to objects then you need to make the linker aware of this folder. If it has not yet been compiled then you need add the source files to your project.

Either cause should be resolved by adding the source files to your project.
 

Thread Starter

syndred

Joined May 6, 2014
13
Thanks for the reply.

That probably is the issue, but I don't think the source is included in the compressed folder I've used.

I'll have a look for them on Github, and then I'll try and work out how to compile that.

Edit : If I'm not mistaken the source is in another compressed folder on sourceforge. But there is absolutely no indication in the documentation as to which subfolder is the one I want to add to my project. Also, since these are C files and I would like to work on a C++ project, is there anything specific I might need to do ?
 
Last edited:

Thread Starter

syndred

Joined May 6, 2014
13
I'm now getting a different type of error when using the new .lib in project(I worked out what I was supposed to compile).

1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>libusb-1.0.lib(core.obj) : error LNK2019: unresolved external symbol _usbi_hotplug_deregister_all referenced in function _libusb_exit@4
1>libusb-1.0.lib(io.obj) : error LNK2019: unresolved external symbol _usbi_hotplug_match referenced in function _handle_events
1>blabla\Visual Studio 2008\Projects\libusbtest3\Debug\libusbtest3.exe : fatal error LNK1120: 2 unresolved externals
 

Thread Starter

syndred

Joined May 6, 2014
13
I've had a thorough look and I think it seems I might be having trouble with the generated .lib file because of the fact that the hotplug functionailty isn't officially supported for versions of VS before 2012 (or maybe 2010, not sure).

I guess unless some libusb knowledgeable person points out that a) I'm wrong, b) there's a really easy hack or c) delete this and that and hey presto, I'll be working with an older version of libusb that doesn't have hotplug support. Since it is the only issue I have and I also can't upgrade VS2008 for this project, I don't see any simpler option.
 
Top