Linking libusb-1.0 to mycfile.c fails - linker

Despite downloading and compiling libusb-1.0 to /usr/local, to know exactky where it is, gcc still can't find it;
gcc -o usb -L/usr/local/lib -llibusb-1.0.so -I/usr/local/include myusbcfile.c
gives;
usbtest.c:4:15: error: storage size of ‘brd_ftdi’ isn’t known
libusb_device brd_ftdi;
^
usbtest.c:5:22: error: storage size of ‘brd_ftdi_handle’ isn’t known
libusb_device_handle brd_ftdi_handle;
^
usbtest.c:6:16: error: storage size of ‘context’ isn’t known
libusb_context context;
^
This clearly indicates gcc can't find the library, tried different forms of this command, everyone giving this error.

I think your problem is this one :
-lxxxx tells the linker : 'find a library called libxxxx', so what you're asking in your command line is to find the library liblibusb-1.0.so
Maybe you should try this :
gcc -o usb -L/usr/local/lib -lusb-1.0.so -I/usr/local/include myusbcfile.c
This way, the linker should be looking for a library called libusb-1.0.so

Related

Why does linking with `mingw32` solve this compilation problem with SDL2?

I'm learning development using SDL2 with C on Windows and Mingw.
I tried the following command to compile my program:
gcc -IC:C:/msys64_new/mingw64/include/SDL2 *.c -o game.exe -g -Wall -Wno-unused -LC:/msys64_new/mingw64/lib -lSDL2main -lSDL2
It gave the error: Undefined reference to WinMain
Then I read that I should add -lmingw32 to the command:
gcc -IC:C:/msys64_new/mingw64/include/SDL2 *.c -o game.exe -g -Wall -Wno-unused -LC:/msys64_new/mingw64/lib -lmingw32 -lSDL2main -lSDL2
And now it works! My questions are:
Why does this solve the problem? What does linking with libmingw32.a do that solves this?
How does gcc find libmingw32.a? I don't seem to have such a file in the folder directed by -LC:/msys64_new/mingw64/lib.
libmingw32 is a part of mingw implementation of C runtime library, including e.g. crt0 and thread-local storage, stuff happening before your main is called. If you ask gcc to inform you what it does under the hood via gcc -v the_rest_of_your_build_command you'll see that it have -lmingw32 anyway in its linking command; it is possible to drop CRT (and CRT0) but that's for another question (and you'll need special handling since ordinary C programs expect CRT to be present).
There are some predefined paths linker search for libraries in. Historically for unix-like systems there are /lib, /usr/lib and so on. As mingw is mostly just ported gcc toolchain it inherits the same paths, just with its installation directory prefix (e.g. c:\mingw-w64\x86_64-w64-mingw32\lib. Check outout of ld --verbose output, specifically SEARCH_DIR.
Now why you need to specify -lmingw32 even though it is there anyway - the only reason is how ld linker resolves dependencies - left to right rule, basically. If one static library depends on another, it needs to be specified first in libraries list (but can be specified multiple times, it will not produce a conflict). In your case, #include <SDL.h> redefines your main function to SDL_main; that way your program don't have defined entry point anymore, but libSDL2main.a have one - simple main or WinMain that does minimal preparation and calls your SDL_main. So, you need to link with -lSDL2main, but by default -lmingw32 is appended last (resulting in e.g. -lSDL2main -lSDL2 -lmingw32), and linker don't search for definition of WinMain in SDL2main, and there is no WinMain in your .os, hence linking error. If you add -lmingw32 -lSDL2main -lSDL2, you have correct dependency chain - CRT0 depends on WinMain which implemented in SDL2main which also depends on SDL2. Default parameters will still add -lmingw32 at the tail, so you'll implicitly have it twice, but as I've said before you're allowed to do so.

What could be causing linking errors when compiling in an Alpine Docker?

I am trying to compile a program within a docker container built from the Alpine 3.7 base image. The program uses argp.h, and includes it as #include <argp.h>. I have installed argp-standalone and verified that it is making it onto the image. The file argp.h is located in usr/include, however when I compile my program using the following commands:
gcc -W -Wall -Wextra -I/usr/include -c -o progname.o progname.c
gcc -largp -o progname progname.o
I get the following error:
progname.o: In function `parse_opt':
progname.c:(.text+0x4c9): undefined reference to `argp_failure'
progname.c:(.text+0x50f): undefined reference to `argp_failure'
progname.c:(.text+0x555): undefined reference to `argp_failure'
progname.c:(.text+0x59b): undefined reference to `argp_failure'
progname.c:(.text+0x5ce): undefined reference to `argp_error'
progname.c:(.text+0x5f4): undefined reference to `argp_error'
progname.o: In function `main':
progname.c:(.text+0x1397): undefined reference to `argp_parse'
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: progname] Error 1
I have:
Ensured that the version of argp.h which is on the image does in fact include the argp_failure, argp_parse, and argp_error functions.
Tried moving argp.h into different locations on the machine (e.g. into the same directory where compilation is taking place, into /usr/lib)
Tried compiling with -l and -L.
The relevant packages also installed in the image are build-base, make, and gcc.
When compiling on an Ubuntu image these same commands work fine, even without the -largp and -I/usr/include flags. What could be happening differently within an Alpine image which would cause this not to work?
Edit
As per #Pablo's comment, I'm now compiling it as follows:
gcc -W -Wall -Wextra -I/usr/include -L/usr/lib -c -o progname.o progname.c
gcc -largp -o progname progname.o
After having verified that the static library, libargp.a, is located in /usr/lib. However, the same problem still persists.
Edit 2
Compiling as follows (and once again as per #Pablo's suggestion) has resolved the error I was having:
gcc -W -Wall -Wextra -I/usr/include -L/usr/lib -c -o progname.o progname.c
gcc -o progname progname.o /usr/lib/libargp.a
However, I am still curious why, using the exact same library and instructions, this would fail to compile in an Alpine image while compiling without issue in an Ubuntu image.
I am still curious why, using the exact same library and instructions, this would fail to compile in an Alpine image while compiling without issue in an Ubuntu image.
The reason for the linking error on Alpine may be kind of surprising, and is actually not specific to Alpine.
While this fails to link:
gcc -largp -o progname progname.o
This works:
gcc -o progname progname.o -largp
The reason is the order of parameters passed to the linker, and it related to the linking algorithm. Typically, in the linking command line objects are specified first (and possibly user's static libraries in any), then libraries using -l. The standard linker algorithm is explained perfectly in Eli Bendersky's article, Library order in static linking:
Object files and libraries are provided in a certain order on the command-line, from left to right. This is the linking order. Here's what the linker does:
The linker maintains a symbol table. This symbol table does a bunch of things, but among them is keeping two lists:
A list of symbols exported by all the objects and libraries encountered so far.
A list of undefined symbols that the encountered objects and libraries requested to import and were not found yet.
When the linker encounters a new object file, it looks at:
The symbols it exports: these are added to the list of exported symbols mentioned above. If any symbol is in the undefined list, it's removed from there because it has now been found. If any symbol has already been in the exported list, we get a "multiple definition" error: two different objects export the same symbol and the linker is confused.
The symbols it imports: these are added to the list of undefined symbols, unless they can be found in the list of exported symbols.
When the linker encounters a new library, things are a bit more interesting. The linker goes over all the objects in the library. For each one, it first looks at the symbols it exports.
If any of the symbols it exports are on the undefined list, the object is added to the link and the next step is executed. Otherwise, the next step is skipped.
If the object has been added to the link, it's treated as described above - its undefined and exported symbols get added to the symbol table.
Finally, if any of the objects in the library has been included in the link, the library is rescanned again - it's possible that symbols imported by the included object can be found in other objects within the same library.
When -largp appears first, the linker does not include any of its objects in the linking procedure, since it doesn't have any undefined symbols yet. If the static library is provided by path, and not with -l, then all of its objects are added to the linking procedure.

The procedure entry point axiom_attribute_create could not be located in the dynamic link library

I have a project in c and I want to compile it in CodeBlocks with MinGW.
I tried to link its needed libraries but I got
undefined reference error
so I searched and found out that the libraries that I was using was compiled with MVC++ and cannot be used with MinGW. (I am not an expert in c, so I'm a little bit confused.) I found This link and did what they said in order to solve my problem.
I have created axis2c .a files from the original axis2c .dll files.
I created .def files with reimp
then I modified each stdcall function in .def files (I changed "_name#ordinal" to "name")
then I used dlltool to create .a files.
I linked the .a files to my project. Everything went fine and I could compile my project. but when I try to run it. I get this error.
The procedure entry point axiom_attribute_create could not be located in the dynamic link library
I have included my project in this Link.
I downloaded a CodeBlocks with MinGW. codeblocks-10.05mingw-setup.exe (which I guess uses MinGw32bit).Then I followed the steps that #mikekinghan said to set up Build Options. Then I built the project. I got this error.
I have already added Axis2c lib folder to path Environment. (I even copied axiom.dll to "C:\Windows\SysWOW64" as #mikekinghan suggested.
Here is the build log :
-------------- Build: Debug in Math ---------------
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\adb_addOperatorResponse.c -o obj\Debug\adb_addOperatorResponse.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
from C:\Tools\axis2c\include/axutil_class_loader.h:31,
from C:\Tools\axis2c\include/axis2_util.h:24,
from E:\dev\c\Math\adb_addOperatorResponse.h:21,
from E:\dev\c\Math\adb_addOperatorResponse.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\adb_addOperatorResponse.c: In function 'adb_addOperatorResponse_serialize_obj':
E:\dev\c\Math\adb_addOperatorResponse.c:466: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
E:\dev\c\Math\adb_addOperatorResponse.c:374: warning: unused variable 'ns_already_defined'
E:\dev\c\Math\adb_addOperatorResponse.c:372: warning: unused variable 'qname_prefix'
E:\dev\c\Math\adb_addOperatorResponse.c:371: warning: unused variable 'qname_uri'
E:\dev\c\Math\adb_addOperatorResponse.c:367: warning: unused variable 'tag_closed'
E:\dev\c\Math\adb_addOperatorResponse.c: In function 'adb_addOperatorResponse_reset_addOperatorReturn':
E:\dev\c\Math\adb_addOperatorResponse.c:568: warning: unused variable 'element'
E:\dev\c\Math\adb_addOperatorResponse.c:567: warning: unused variable 'count'
E:\dev\c\Math\adb_addOperatorResponse.c:566: warning: unused variable 'i'
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\axis2_extension_mapper.c -o obj\Debug\axis2_extension_mapper.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
from C:\Tools\axis2c\include/axutil_class_loader.h:31,
from C:\Tools\axis2c\include/axis2_util.h:24,
from E:\dev\c\Math\axis2_extension_mapper.h:14,
from E:\dev\c\Math\axis2_extension_mapper.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\axis2_extension_mapper.c: In function 'axis2_extension_mapper_type_from_node':
E:\dev\c\Math\axis2_extension_mapper.c:31: warning: unused variable 'element_qname'
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\axis2_stub_MathService.c -o obj\Debug\axis2_stub_MathService.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
from C:\Tools\axis2c\include/axutil_class_loader.h:31,
from C:\Tools\axis2c\include/axis2_util.h:24,
from C:\Tools\axis2c\include/neethi_includes.h:22,
from C:\Tools\axis2c\include/neethi_operator.h:29,
from C:\Tools\axis2c\include/neethi_policy.h:29,
from C:\Tools\axis2c\include/axis2_svc_client.h:56,
from C:\Tools\axis2c\include/axis2_stub.h:35,
from C:\Tools\axis2c\include/axis2_client.h:31,
from E:\dev\c\Math\axis2_stub_MathService.h:14,
from E:\dev\c\Math\axis2_stub_MathService.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\axis2_stub_MathService.c: In function 'axis2_stub_populate_services_for_MathService':
E:\dev\c\Math\axis2_stub_MathService.c:72: warning: unused variable 'status'
E:\dev\c\Math\axis2_stub_MathService.c:71: warning: unused variable 'neethi_policy'
E:\dev\c\Math\axis2_stub_MathService.c:70: warning: unused variable 'policy_root_ele'
E:\dev\c\Math\axis2_stub_MathService.c:69: warning: unused variable 'policy_node'
E:\dev\c\Math\axis2_stub_MathService.c:68: warning: unused variable 'desc'
E:\dev\c\Math\axis2_stub_MathService.c:66: warning: unused variable 'policy_include'
E:\dev\c\Math\axis2_stub_MathService.c: In function 'axis2_stub_on_complete_MathService_addOperator':
E:\dev\c\Math\axis2_stub_MathService.c:277: warning: unused variable 'soap_fault'
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\main.c -o obj\Debug\main.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
from C:\Tools\axis2c\include/axutil_class_loader.h:31,
from C:\Tools\axis2c\include/axis2_util.h:24,
from C:\Tools\axis2c\include/neethi_includes.h:22,
from C:\Tools\axis2c\include/neethi_operator.h:29,
from C:\Tools\axis2c\include/neethi_policy.h:29,
from C:\Tools\axis2c\include/axis2_svc_client.h:56,
from C:\Tools\axis2c\include/axis2_stub.h:35,
from C:\Tools\axis2c\include/axis2_client.h:31,
from E:\dev\c\Math\axis2_stub_MathService.h:14,
from E:\dev\c\Math\main.c:1:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\main.c:3: warning: second argument of 'main' should be 'char **'
E:\dev\c\Math\main.c: In function 'main':
E:\dev\c\Math\main.c:8: warning: unused variable 'operation'
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\adb_addOperator.c -o obj\Debug\adb_addOperator.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
from C:\Tools\axis2c\include/axutil_class_loader.h:31,
from C:\Tools\axis2c\include/axis2_util.h:24,
from E:\dev\c\Math\adb_addOperator.h:21,
from E:\dev\c\Math\adb_addOperator.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\adb_addOperator.c: In function 'adb_addOperator_serialize_obj':
E:\dev\c\Math\adb_addOperator.c:574: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
E:\dev\c\Math\adb_addOperator.c:640: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
E:\dev\c\Math\adb_addOperator.c:480: warning: unused variable 'ns_already_defined'
E:\dev\c\Math\adb_addOperator.c:478: warning: unused variable 'qname_prefix'
E:\dev\c\Math\adb_addOperator.c:477: warning: unused variable 'qname_uri'
E:\dev\c\Math\adb_addOperator.c:473: warning: unused variable 'tag_closed'
E:\dev\c\Math\adb_addOperator.c: In function 'adb_addOperator_reset_num1':
E:\dev\c\Math\adb_addOperator.c:742: warning: unused variable 'element'
E:\dev\c\Math\adb_addOperator.c:741: warning: unused variable 'count'
E:\dev\c\Math\adb_addOperator.c:740: warning: unused variable 'i'
E:\dev\c\Math\adb_addOperator.c: In function 'adb_addOperator_reset_num2':
E:\dev\c\Math\adb_addOperator.c:848: warning: unused variable 'element'
E:\dev\c\Math\adb_addOperator.c:847: warning: unused variable 'count'
E:\dev\c\Math\adb_addOperator.c:846: warning: unused variable 'i'
mingw32-g++.exe -LC:\Tools\axis2c\include -LE:\dev\CodeBlocks\MinGW\lib -o bin\Debug\Math.exe obj\Debug\adb_addOperatorResponse.o obj\Debug\axis2_extension_mapper.o obj\Debug\axis2_stub_MathService.o obj\Debug\main.o obj\Debug\adb_addOperator.o -laxiom -laxutil -laxis2_engine -laxis2_parser
e:/dev/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../../mingw32/bin/ld.exe: cannot find -laxiom
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 6 seconds)
1 errors, 35 warnings
It seems that I made a mistake putting ../include in Search Directories>Linker I fixed that mistake.
I build the project then I get this :
-------------- Build: Debug in Math ---------------
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\adb_addOperatorResponse.c -o obj\Debug\adb_addOperatorResponse.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
from C:\Tools\axis2c\include/axutil_class_loader.h:31,
from C:\Tools\axis2c\include/axis2_util.h:24,
from E:\dev\c\Math\adb_addOperatorResponse.h:21,
from E:\dev\c\Math\adb_addOperatorResponse.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\adb_addOperatorResponse.c: In function 'adb_addOperatorResponse_serialize_obj':
E:\dev\c\Math\adb_addOperatorResponse.c:466: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\axis2_extension_mapper.c -o obj\Debug\axis2_extension_mapper.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
from C:\Tools\axis2c\include/axutil_class_loader.h:31,
from C:\Tools\axis2c\include/axis2_util.h:24,
from E:\dev\c\Math\axis2_extension_mapper.h:14,
from E:\dev\c\Math\axis2_extension_mapper.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\axis2_stub_MathService.c -o obj\Debug\axis2_stub_MathService.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
from C:\Tools\axis2c\include/axutil_class_loader.h:31,
from C:\Tools\axis2c\include/axis2_util.h:24,
from C:\Tools\axis2c\include/neethi_includes.h:22,
from C:\Tools\axis2c\include/neethi_operator.h:29,
from C:\Tools\axis2c\include/neethi_policy.h:29,
from C:\Tools\axis2c\include/axis2_svc_client.h:56,
from C:\Tools\axis2c\include/axis2_stub.h:35,
from C:\Tools\axis2c\include/axis2_client.h:31,
from E:\dev\c\Math\axis2_stub_MathService.h:14,
from E:\dev\c\Math\axis2_stub_MathService.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\main.c -o obj\Debug\main.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
from C:\Tools\axis2c\include/axutil_class_loader.h:31,
from C:\Tools\axis2c\include/axis2_util.h:24,
from C:\Tools\axis2c\include/neethi_includes.h:22,
from C:\Tools\axis2c\include/neethi_operator.h:29,
from C:\Tools\axis2c\include/neethi_policy.h:29,
from C:\Tools\axis2c\include/axis2_svc_client.h:56,
from C:\Tools\axis2c\include/axis2_stub.h:35,
from C:\Tools\axis2c\include/axis2_client.h:31,
from E:\dev\c\Math\axis2_stub_MathService.h:14,
from E:\dev\c\Math\main.c:1:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\main.c:3: warning: second argument of 'main' should be 'char **'
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\adb_addOperator.c -o obj\Debug\adb_addOperator.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
from C:\Tools\axis2c\include/axutil_class_loader.h:31,
from C:\Tools\axis2c\include/axis2_util.h:24,
from E:\dev\c\Math\adb_addOperator.h:21,
from E:\dev\c\Math\adb_addOperator.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\adb_addOperator.c: In function 'adb_addOperator_serialize_obj':
E:\dev\c\Math\adb_addOperator.c:574: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
E:\dev\c\Math\adb_addOperator.c:640: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
mingw32-g++.exe -LC:\Tools\axis2c\lib -LE:\dev\CodeBlocks\MinGW\lib -o bin\Debug\Math.exe obj\Debug\adb_addOperatorResponse.o obj\Debug\axis2_extension_mapper.o obj\Debug\axis2_stub_MathService.o obj\Debug\main.o obj\Debug\adb_addOperator.o -laxiom -laxutil -laxis2_engine -laxis2_parser
obj\Debug\adb_addOperatorResponse.o: In function `adb_addOperatorResponse_create':
E:/dev/c/Math/adb_addOperatorResponse.c:58: undefined reference to `_imp__axutil_error_set_error_number'
E:/dev/c/Math/adb_addOperatorResponse.c:58: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:64: undefined reference to `_imp__axutil_strdup'
E:/dev/c/Math/adb_addOperatorResponse.c:67: undefined reference to `_imp__axutil_qname_create'
obj\Debug\adb_addOperatorResponse.o: In function `adb_addOperatorResponse_free_obj':
E:/dev/c/Math/adb_addOperatorResponse.c:139: undefined reference to `_imp__axutil_error_set_error_number'
E:/dev/c/Math/adb_addOperatorResponse.c:139: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:139: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:150: undefined reference to `_imp__axutil_qname_free'
obj\Debug\adb_addOperatorResponse.o: In function `adb_addOperatorResponse_deserialize_obj':
E:/dev/c/Math/adb_addOperatorResponse.c:209: undefined reference to `_imp__axutil_error_set_error_number'
E:/dev/c/Math/adb_addOperatorResponse.c:209: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:209: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:215: undefined reference to `_imp__axiom_node_get_next_sibling'
E:/dev/c/Math/adb_addOperatorResponse.c:213: undefined reference to `_imp__axiom_node_get_node_type'
E:/dev/c/Math/adb_addOperatorResponse.c:227: undefined reference to `_imp__axiom_node_get_data_element'
E:/dev/c/Math/adb_addOperatorResponse.c:228: undefined reference to `_imp__axiom_element_get_qname'
E:/dev/c/Math/adb_addOperatorResponse.c:229: undefined reference to `_imp__axutil_qname_equals'
E:/dev/c/Math/adb_addOperatorResponse.c:232: undefined reference to `_imp__axiom_node_get_first_child'
E:/dev/c/Math/adb_addOperatorResponse.c:237: undefined reference to `_imp__axutil_qname_to_string'
E:/dev/c/Math/adb_addOperatorResponse.c:237: undefined reference to `_imp__axutil_qname_to_string'
E:/dev/c/Math/adb_addOperatorResponse.c:260: undefined reference to `_imp__axiom_node_get_next_sibling'
E:/dev/c/Math/adb_addOperatorResponse.c:258: undefined reference to `_imp__axiom_node_get_node_type'
E:/dev/c/Math/adb_addOperatorResponse.c:264: undefined reference to `_imp__axiom_node_get_data_element'
E:/dev/c/Math/adb_addOperatorResponse.c:265: undefined reference to `_imp__axiom_element_get_qname'
E:/dev/c/Math/adb_addOperatorResponse.c:268: undefined reference to `_imp__axutil_qname_create'
E:/dev/c/Math/adb_addOperatorResponse.c:272: undefined reference to `_imp__axutil_qname_equals'
E:/dev/c/Math/adb_addOperatorResponse.c:274: undefined reference to `_imp__axutil_qname_equals'
E:/dev/c/Math/adb_addOperatorResponse.c:280: undefined reference to `_imp__axiom_element_get_text'
E:/dev/c/Math/adb_addOperatorResponse.c:298: undefined reference to `_imp__axutil_qname_free'
E:/dev/c/Math/adb_addOperatorResponse.c:308: undefined reference to `_imp__axutil_qname_free'
E:/dev/c/Math/adb_addOperatorResponse.c:317: undefined reference to `_imp__axutil_qname_free'
obj\Debug\adb_addOperatorResponse.o: In function `adb_addOperatorResponse_serialize_obj':
E:/dev/c/Math/adb_addOperatorResponse.c:392: undefined reference to `_imp__axutil_error_set_error_number'
E:/dev/c/Math/adb_addOperatorResponse.c:392: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:392: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:395: undefined reference to `_imp__axutil_hash_make'
E:/dev/c/Math/adb_addOperatorResponse.c:398: undefined reference to `_imp__axiom_namespace_create'
E:/dev/c/Math/adb_addOperatorResponse.c:401: undefined reference to `_imp__axutil_strdup'
E:/dev/c/Math/adb_addOperatorResponse.c:401: undefined reference to `_imp__axutil_hash_set'
E:/dev/c/Math/adb_addOperatorResponse.c:404: undefined reference to `_imp__axiom_element_create'
E:/dev/c/Math/adb_addOperatorResponse.c:407: undefined reference to `_imp__axiom_element_set_namespace'
E:/dev/c/Math/adb_addOperatorResponse.c:411: undefined reference to `_imp__axiom_data_source_create'
E:/dev/c/Math/adb_addOperatorResponse.c:412: undefined reference to `_imp__axiom_data_source_get_stream'
E:/dev/c/Math/adb_addOperatorResponse.c:414: undefined reference to `_imp__axutil_hash_get'
E:/dev/c/Math/adb_addOperatorResponse.c:418: undefined reference to `_imp__axutil_hash_set'
E:/dev/c/Math/adb_addOperatorResponse.c:420: undefined reference to `_imp__axiom_namespace_create'
E:/dev/c/Math/adb_addOperatorResponse.c:420: undefined reference to `_imp__axiom_element_declare_namespace_assume_param_ownership'
E:/dev/c/Math/adb_addOperatorResponse.c:436: undefined reference to `_imp__axutil_strlen'
E:/dev/c/Math/adb_addOperatorResponse.c:436: undefined reference to `_imp__axutil_strlen'
E:/dev/c/Math/adb_addOperatorResponse.c:441: undefined reference to `_imp__axutil_strlen'
E:/dev/c/Math/adb_addOperatorResponse.c:441: undefined reference to `_imp__axutil_strlen'
E:/dev/c/Math/adb_addOperatorResponse.c:458: undefined reference to `_imp__axutil_strcmp'
Process terminated with status 1 (0 minutes, 9 seconds)
50 errors, 9 warnings
Form what #MikeKinghan tried to teach me, I understand the meaning of Linker commands now, and I see that the Linker is set correctly this time. but why can't it compile properly?
Your project contains 5 source files, which each has to be successfully compiled, and then all
need linked together, along with some axis2c DLLs, to build your program.
Let's look at your build log.
There is a compile command for each of the 5 source files:
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\adb_addOperatorResponse.c -o obj\Debug\adb_addOperatorResponse.o
...
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\axis2_extension_mapper.c -o obj\Debug\axis2_extension_mapper.o
...
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\axis2_stub_MathService.c -o obj\Debug\axis2_stub_MathService.o
...
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\main.c -o obj\Debug\main.o
...
mingw32-gcc.exe -Wall -g -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW -c E:\dev\c\Math\adb_addOperator.c -o obj\Debug\adb_addOperator.o
...
and then there is a link command:
mingw32-g++.exe -LC:\Tools\axis2c\include -LE:\dev\CodeBlocks\MinGW\lib -o bin\Debug\Math.exe obj\Debug\adb_addOperatorResponse.o obj\Debug\axis2_extension_mapper.o obj\Debug\axis2_stub_MathService.o obj\Debug\main.o obj\Debug\adb_addOperator.o -laxiom -laxutil -laxis2_engine -laxis2_parser
...
Copy/paste these commands out somewhere where you can see them from end to end.
In all of the places where I have put '...', the compiler or linker has emitted some complaint about your program.
All of the diagnostics emitted by the 5 compile commands are warnings. Whatever is not right, it doesn't actually stop the compiler from compiling the source
file (.c) into an object file (.o). If there had been any compilation errors in any .c file, then the compiler would not have been able to create the .o file,
and the build would have stopped without attempting to link the program, because linking it when some object files are missing would be futile.
This does not mean you don't have to bother about the compiler warnings. They might be warnings about possible bugs in your program, and some of them are.
So you'll need to fix them.
The link command has failed. You have no program, which is your top problem.
In order to make sense of compiler and linker diagnostics, and be able to fix them yourself, you need to understand what the compiler and linker commands mean.
We can see that the toolchain Code::Blocks is driving for you is the MinGW project's 32-bit Windows port of GCC (The GNU Compiler Collection).
GCC is the daddy of C/C++ programming toolchains: it's supported for every operating system and every processor; it's used in every application domain.
It's completely independent of any of the numerous IDEs that you can get to drive it, and all of those IDEs (Eclipse, Code::Blocks, KDevelop, CodeLite, Anjuta,
Dev-C++, etc.) come to you with the implicit assumption that you understand compiling and linking with GCC. At least, none of them can save you from having
to understand compiling and linking with GCC.
Before going any further then, the life-lesson of all this is going to be: Kick away your IDE for a while. Learn about building programs with GCC, itself.
Then it will be obvious how to do it with your IDE.
All of your compile commands are executed by mingw32-gcc.exe. That's the GCC tool-driver, in its C compiler "posture". If you look in the directory where it's installed,
maybe C:\MinGW\bin, you'll see also programs gcc.exe, g++.exe, plus those two with the prefix mingw32-. All of these programs
are the GCC tool driver, in different "postures" adapted to different roles.
Your link command is executed by mingw32-g++.exe. That's the GCC tool-driver again, in its C++ linker "posture". It may seem puzzling that Code::Blocks
by default configures the C++ linker to link C programs. It does that because C++ linkage works for programs that are all C, all C++, or a mixture of the two.
But C linkage won't work for C++ programs.
Whatever "posture" is suggested by the name, the GCC tool driver figures out what needs to be done by inspecting the options on its commandline and the file extensions
of the files that are passed to it. So it tries to compile each of your .c source files as C because they are .c files.
If they were .cpp files then it would try to compile them as C++. Once it figures out what it do, it delegates the work to an appropriate specialized tool -
C compiler, C++ compiler, assembler, linker.
Here's what each of your compile commands means:
-Wall => Enable all warnings
-g => Generate debugging information in the object file.
-IC:\Tools\axis2c\include => Search for non-standard header files in C:\Tools\axis2c\include
-IE:\dev\CodeBlocks\MinGW => Also search for non-standard header files in E:\dev\CodeBlocks\MinGW
-c => Just compile; don't link
E:\dev\c\Math\some_filename.c => Compile this file.
-o obj\Debug\some_filename.o => Output the object file obj\Debug\some_filename.o
And here's what your link command means:
-LC:\Tools\axis2c\include => Search for non-standard libraries (.lib, .a, .dll) in C:\Tools\axis2c\include
-LE:\dev\CodeBlocks\MinGW\lib => Also search for non-standard libraries in E:\dev\CodeBlocks\MinGW\lib
-o bin\Debug\Math.exe => Output the executable bin\Debug\Math.exe
obj\Debug\adb_addOperatorResponse.o => Link this object file
obj\Debug\axis2_extension_mapper.o => Also link this object file
obj\Debug\axis2_stub_MathService.o => Also link this object file
obj\Debug\main.o => Also link this object file
obj\Debug\adb_addOperator.o => Also link this object file
-laxiom => Link the libary axiom.dll or failing that, axiom.lib or libaxiom.a, wherever it is first found in the specified linker
search directories (-L), or failing that in the linker's standard directories.
-laxutil => Link the libary axutil.dll or failing that, axutil.lib or libaxutil.a, etc...
-laxis2_engine => Link the libary axis2_engine.dll or failing that, axis2_engine.lib or libaxis2_engine.a, etc...
-laxis2_parser => Link the libary axis2_parser.dll or failing that, axis2_parser.lib or libaaxis2_parser.a, etc...
You might wonder how the tool-driver knows that the link command is a link command, and not perhaps a C++ compile command?
It knows there is no compiling to do because none of the input files can be compiled. They are all object files (.o).
And it knows it is supposed to link them because it hasn't been told not to link them: the -c option is absent.
You linkage failed because:
e:/dev/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../../mingw32/bin/ld.exe: cannot find -laxiom
ld.exe is the linker itself: the specialized tool that the GCC tool driver invokes when there is linking to be done.
It can't find your axiom library in any of the linker search directories you specified (-L), nor, of course, in
any of the standard search directories.
Now that you understand the meaning of your link command, it will be easy for you to see what's wrong. The linker
search directories that you specified are:
C:\Tools\axis2c\include
E:\dev\CodeBlocks\MinGW\lib
and your axis2c libraries (axiom.dll etc) aren't in either of those places. C:\Tools\axis2c\include
is the same place where you told the compiler to search for the axis2c header files: you have:
-IC:\Tools\axis2c\include
So if that's where the axis2c header files are, then the libraries, I guess, are in C:\Tools\axis2c\lib. Have a look.
Assuming that's right, then in the C::B IDE you need to delete the wrong C:\Tools\axis2c\include from Search directories -> Linker
for your project and replace it with the correct C:\Tools\axis2c\lib Leave C:\Tools\axis2c\include in Search directories -> Compiler,
because that is correct.
Continued for OP's further issues
I believe that your axis2c libraries and header files originated from Apache's Axis2/C download page
from the archive axis2c-bin-1.6.0-win32.zip.
This release suffers from a bug in its header files that causes the linkage errors
you are seeing with the MinGW32 toolchain.
This bug does not affect Google's release of Axis2/C that I referred you to
in my first answer to this question. At that time you said that you were building with 64-bit MinGW, but it has since
become clear that you are building with 32-bit MinGW. In that case, you should download Google's 32-bit build Axis2/C
Unzip the archive with 7-Zip and rename the unzipped folder from axis2c to axis2c-x86-google, to make clear what it is, then copy it somewhere convenient
for your development. Let's say you put it at C:\Tools\axis2c-x86-google.
Then in the C::B IDE, in Search directories -> Compiler, change:
C:\Tools\axis2c\include
to:
C:\Tools\axis2c-x86-google\include\axis2-1.6.0
and in Search directories -> Linker, change:
C:\Tools\axis2c\lib
to:
C:\Tools\axis2c-x86-google\lib
The library that is called axiom.dll in the Apache release is called axis2_axiom.dll in Google's release. Therefore
in your Linker settings -> Other linker options, change:
-laxiom
to:
-laxis2_axiom
Your program then links successfully (for me).
Continued again
Per your comments, the program now fails to load at runtime with the error:
The procedure entry point axis2_callback_create could not be located in the dynamic link library
This means the correct DLL providing axis2_callback_create is not found at runtime.
You say:
I also added the "lib" to path environment. and also added the lib dll files to "C:\Windows\SysWOW64"
Do one or the other, not both.
Depending on what you did to add the Axis2/C library directory to the PATH, it may have had no effect.
If you did this in a shell (command prompt) window that was not the very same one in which your tried to run your
program, then it will have had no effect, since environment settings that you make in a shell apply only to
processes launched in the same shell.
If you did this by modifying the PATH environment variable in Advanced System Settings then that will have
no effect on a shell already open in which you tried to run your program. You would need save the Advanced System Settings
and then try again to run your program in a new shell.
I am able to start your program without DLL errors in all of the following ways:
With all of the files C:\Tools\axis2c-x86-google\lib\*.dll located in the same directory with Math.exe
With all of the files C:\Tools\axis2c-x86-google\lib\*.dll located instead in C:Windows\SysWOW64
In a shell window in which I have previously run: set PATH=%PATH%;C:\path\to\my\axis2c-x86-google\lib
In a new shell after I have added C:\path\to\my\axis2c-x86-google\lib to the PATH environment
variable in Advanced System Settings.
If none of them works for you then I'm afraid the problem is beyond me :(
I don't follow the reasoning behind the steps you have taken and don't
have any concrete data about what you did, so this is an answer "from first principles".
If you want to link a DLL foo.dll with your program using Microsoft's linker (which you are not doing) you cannot
pass foo.dll directly to the linker. As you know, you must instead pass an import library, foo.lib, which is
a small static library of "stubs" representing the functions that are exported by foo.dll. At runtime,
the program loader scans these stubs and (if possible) replaces them with matching references to
to exported functions that it finds by searching available DLLs according to the Windows DLL Search Path
If you want to link foo.dll with your program using the MinGW GNU linker (which you are doing), no
import library foo.lib is necessary. This linker can link foo.dll directly. There is no reason for you to
do otherwise.
To link foo.dll directly with your program using the MinGW GNU linker, the linker, of course,
must be able to find foo.dll at linktime by the the rules that it follows to find libraries, whether static or
dynamic. And just as with Microsoft's linker, successful linkage of a DLL does not guarantee that the DLL
will also be found at runtime by the program loader. The program loader searches for DLLs according to
the the Windows DLL Search Path: it doesn't know or care which linker you used to link your program. You
have to make sure that the linker finds the DLL at linktime, and then you need to make sure that the program
loader will find it at runtime.
How do you tell the MinGW linker to link foo.dll directly? You just follow the rules for passing libraries to
the linker, as documented here.
But before you can attempt that there is one other basic condition that has to be satisfied. You
can't link a 32-bit DLL with a 64-bit program, or vice versa. You say you are building with 64-bit MinGW;
so by default it will build 64-bit executables, and if your are building a 64-bit .exe then you must link it with 64-bit builds of the axis2c DLLs.
I don't know where you got your axis2c libraries, but if you downloaded Apache's v1.6.0 binary archive
then you have got 32-bit DLLs.
You could tell your 64-bit MinGW to build a 32-bit .exe, but you'd probably prefer to link it with 64-bit axis2c DLLs. Fortunately,
a 64-bit build is provided by Google. Download it from here. The 64-bit archive is
x86_64-wsdk7.1-r7acae470da50.7z.
Download it somewhere convenient; extract it with 7-Zip, and then I suggest you rename the extracted folder to something that will identify it
clearly, like axis2c-x86_64-google.
Now, I'll compile and link at the command prompt an example axis2c program, following the linker's rules for finding libraries.
The program I'll build is one of the sample programs provided in the Apache package: axis2c-bin-1.6.0-win32\samples\src\client\echo.
I picked it at random: it contains only one source file, which is echo.c. My toolchain is 64-bit GCC 4.9.2. I have my 64-bit axis2c package downloaded, unzipped and renamed as
C:\develop\stackoverflow\axis2c-x86_64-google
I open a command prompt in the echo directory and enter:
gcc -IC:\develop\stackoverflow\axis2c-x86_64-google\include\axis2-1.6.0 -c echo.c -o echo.o
I'm telling gcc to compile echo.c to echo.o, and that it should search for non-standard header files
in C:\develop\stackoverflow\axis2c-x86_64-google\include\axis2-1.6.0. (To understand basically how to compile and
link programs with GCC, I suggest you read this tutorial).
I get a compiler warning:
warning Please include winsock2.h before windows.h
but it's not an error so I'm not going to worry about it for the purposes of this demonstration.
Next, I want to link the echo.o I've just built with the axis2c DLLs that it requires to
make a program called axis2c-echo.exe. So I enter:
gcc -o axis2c-echo.exe echo.o -LC:\develop\stackoverflow\axis2c-x86_64-google\lib -laxiom -laxutil -laxis2_engine -laxis2_parser
I'm telling gcc that besides the object file echo.o, the program needs to link the libraries (-l) axiom, axutil, axis2_engine and axis2_parser,
and that the linker should look for non-standard libraries in C:\develop\stackoverflow\axis2c-x86_64-google\lib.
Notice that I don't need to tell the linker that, say, the axiom library is axiom.dll and not axiom.lib or libaxiom.a. -laxiom tells the
linker to look for any of these in a given search directory and if it happens to finds a dynamic library (axiom.dll) it will prefer it to any static
library axiom.lib or libaxiom.a. In C:\develop\stackoverflow\axis2c-x86_64-google\lib it will in fact find both axiom.dll and axiom.lib,
and prefer the former; but you don't need to care.
The linkage command succeeds, so now I have a program, axis2c-echo.exe in the same directory. I'll run it:
axis2c-echo
But I can't. I just get a Windows error dialog that says:
This program can't start because axiom.dll is missing from your computer. Try reinstalling the program to fix this error.
The problem is that axiom.dll was linked from C:\develop\stackoverflow\axis2c-x86_64-google\lib, which is not one of the
places where the program loader searches for DLLs at runtime.
Now if I planned to be regularly running axis2c programs on my computer, I would solve this by installing the 64-bit axis2c DLLs
in C:\Windows\SysWOW64, because 64-bit Windows always searches for DLLs there. But I don't plan to do that, so instead I'll just
temporarily add C:\develop\stackoverflow\axis2c-x86_64-google\lib to the Windows DLL Search Path. The last stop on the Windows DLL Search Path
is: The directories listed in the PATH environment variable. So at my command prompt I'll enter:
set PATH=%PATH%;C:\develop\stackoverflow\axis2c-x86_64-google\lib
and then run axis2c-echo again. This time, the output is:
AXIS2C_HOME is not set - log is written to . dir
Using endpoint : http://localhost:9090/axis2/services/echo
Error creating service client, Please check AXIS2C_HOME again
Now the program itself is complaining, but that's good enough for me! It has compiled, linked, loaded,
produced some output and finished gracefully.
It's probably obvious now how you would set up a Code::Blocks project to build this same program:
Create a C-language console project in the echo directory.
Delete the default main.c source file from the project
Add the single source file echo.c to the project.
In the project's Build options -> Search directories -> Compiler, add C:\develop\stackoverflow\axis2c-x86_64-google\include\axis2-1.6.0
(or path\to\your\axis2c-1.6.0\header-files)
In the project's Build options -> Search directories -> Linker, add C:\develop\stackoverflow\axis2c-x86_64-google\lib
(or path\to\your\axis2c-1.6.0\libraries)
In the project's Build options -> Linker settings -> Other linker options, add -laxiom -laxutil -laxis2_engine -laxis2_parser
This isn't the only way you could successfully configure this project in C::B, but it corresponds to the way someone would normally build the
project at the command prompt, and means that the toolchain commands that C::B executes will be concise and normal-looking.
If you follow these steps to build the example echo project you shouldn't have much difficulty successfully configuring your own project.

C compilation errors: undeclared (first use in this function)

On the PI, I needed the i2c.so library using this git: https://github.com/silentbobbert/pi_sensors. When running makefile from this git to get the i2c.so, i received this error:
Here are the .c and the .h files:
https://github.com/silentbobbert/pi_sensors/tree/master/Info/LinuxInterface
For reference, here is the contents of makefile:
SHELL = /bin/sh
CC = gcc
FLAGS = -c -Wall -Werror -fpic
DEBUGFLAGS = -O0 -D _DEBUG
RELEASEFLAGS = -O2 -D NDEBUG
TARGET = i2c.so
SOURCES = $(shell echo *.c)
HEADERS = $(shell echo *.h)
OBJECTS = $(SOURCES:.c=.o)
PREFIX = $(DESTDIR)/usr/local
BINDIR = $(PREFIX)/bin
all:
$(CC) $(FLAGS) $(RELEASEFLAGS) $(SOURCES)
$(CC) -shared -o $(TARGET) $(OBJECTS)
as others have said, this is C code not C#.
Anyhow, you have two errors (and they do not relate directly) to the makefile but rather your compilation environment and the code itself.
OK, so how to approach something like this. First notice the first line in your screen-capture, that is the command that is being executed that is generating the error messages, I'll reproduce it here for you;
gcc -c -Wall -Werror -fpic -O2-D NDEBUG i2c_get.c i2c_set.c i2cbusses.c i2cset.c util.c
With this command we are compiling (note the -c flag) a bunch of source files into a single object file, the presence of the `c' flag implies that no linking is performed here. This is relevant so we know where along the tool-chain we are, and the type of errors we can expect (typically either syntax errors or missing header files).
The first error;
i2cset.c: In function 'check_funcs'
i2cset.c:56:2 error: implicit declaration of function 'iotcl' [-Werror=implicit-function-declaration]
is kinda saying, "hey, I can see that ioctl is a function, but you haven't told me anything about it so I'm going to assume that its signature is int ioctl() — a function with an indeterminate (but fixed, not variadic) argument list that returns an int". Given that you are compiling on a Linux-based system, adding #include <sys/ioctl.h> to the top of the file should fix this error.
The second error;
i2cset.c:63:7: error: 'I2C_SMBUS_BYTE' undeclared (first use in this function)
is related to the first error; and it is kinda saying 'hey, you haven't told me anything about I2C_SMBUS_BYTE'. Again, the most common reason for seeing this error is a missing header file. Looking at the source files you've provided a link to, it seems that I2C_SMBUS_BYTE is defined in
the header file i2c-dev.h, which however appears to be included in i2cset.c by: #include <linux/i2c-dev.h>.
At this point I'd insure that your compiler (gcc) can find the header file. From the error messages you are getting, I'm guessing that it is not, but you should be seeing an error message from the compiler about not being able to find the file. Also, if the file is on your system check to see if has the appropriate contents as compared to the git site.
Finally, the remain errors that you are seeing should be fixed as well as they are all basically the same thing.

Can't link against WinPcap library wpcap.lib ("undefined reference to")

I am trying to build an example program which uses WinPcap-functions. I’m working under Windows 7 64 Bit edition with MinGW. I am able to compile the C-code to an object file, but I can’t link against wpcap.lib.
My linker call looks like this:
gcc -L ../../lib/x64 send_packet.o -lwpcap -o WinPcapTest.exe
With this call I get the following errors:
undefined reference to pcap_open
undefined reference to pcap_sendpacket
undefined reference to pcap_geterr
Obviously I am not linking against wpcap.lib, but I don’t know why. The library is definitely found. If I change the lib include path for example, I get this error:
cannot find -lwpcap
Why does the linker find the lib but does not link against it? Thanks for your help.
Try listing you libraries after binary definition. As far as I remember, with provided gcc command, ld would be symbol matching for pcap symbols between send_packet.o and libwpcap.lib but not with WinPcapTest.exe. I would suggest moving -lwpcap at the end:
gcc -I ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Include ..\send_packet.c -L ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Lib\x64 -O0 -g3 -Wall -o WinPcapTest.exe -lwpcap

Resources