gSOAP - Undefined References Error in Windows using gcc.exe - c

I'm basically a java developer and i have a web services created using java. Now I need a client coded with C , to consume that java WS. After surfing a lot, I landed with gSOAP cos of its support of WS.
Now, I was able to generate the header file and also the corresponding stub classes. I also have created a main class that will invoke the actual proxy method., but for some reasons my code is not getting compiled at all.
Steps of what am I doing:
wsdl2h.exe -c -o calc.h calc.wsdl
soapcpp2.exe -C calc.h
gcc.exe -o CalcClient CalcClient.c soapC.c soapClient.c stdsoap2.c
The first two steps are fine, but its only the 3 step thats giving the trouble with the undefined references error. Please note that am running the above in windows platform and the gcc compiler is provided by Bloodshed Dev tool.
The error that i get when performing step 3 is (copied a few lines..),
CalcClient.C:5: undefined reference to soap_new_LIBRARY_VERSION_REQUIRED_20816'
CalcClient.C:7: undefined reference tosoap_call_ns2__add'
CalcClient.C:10: undefined reference to soap_print_fault'
CalcClient.C:11: undefined reference tosoap_end'
and
C:\TEMP/ccS0iaaa.o(.text+0x129):stdsoap2.c: undefined reference to sendto#24'
C:\TEMP/ccS0iaaa.o(.text+0x154):stdsoap2.c: undefined reference tosend#16'
C:\TEMP/ccS0iaaa.o(.text+0x224):stdsoap2.c: undefined reference to sendto#24'
C:\TEMP/ccS0iaaa.o(.text+0x24f):stdsoap2.c: undefined reference tosend#16'
C:\TEMP/ccS0iaaa.o(.text+0x28b):stdsoap2.c: undefined reference to WSAGetLastError#0'
C:\TEMP/ccS0iaaa.o(.text+0x4a9b):stdsoap2.c: undefined reference toinet_addr#4
I know am definitely doing something wrong (as i'm new to C).I tried all the options which I can think of, Could you please help me out here?

I had the similar problem. It was mainly because i was not including stdsoap2.cpp or stdsoap2.c. I coppied stdsoap2.cpp file into the project folder from gsoap folder, then i ran the program and it worked fine.

Related

Failing to compile a 15+ year old MUD codebase written in C

I used this codebase to run a mud in the early 2000s, and through that, to teach myself some very elementary coding.
I just got a copy of the codebase from the administrator/coder who ran the server before me, and I'm just about certain that it would compile as-is back then, but now it won't.
My only guess is that it has something to do with updates to GCC in the last 15-20 years, but I'm admittedly a novice and pretty out of my depth here.
This is the error I get after about a hundred pages of warnings when I try to compile it using make:
[18:24:54] finger.c ...
In file included from finger.c:10:0:
../src/include/merc.h:5149:13: warning: inline function ‘check_toughness’ declared but never defined
inline int check_toughness args( ( CD *ch, CD *victim, int dam));
^~~~~~~~~~~~~~~
[18:24:54] Linking Executable ...
obj/fight.o: In function `group_gain':
tbw/reloaded/src/fight.c:5514: undefined reference to `xp_compute'
tbw/reloaded/src/fight.c:5516: undefined reference to `xp_compute'
tbw/reloaded/src/fight.c:5518: undefined reference to `xp_compute'
obj/fight.o: In function `one_hit':
tbw/reloaded/src/fight.c:2457: undefined reference to `check_toughness'
obj/mage.o: In function `do_chant':
tbw/reloaded/src/mage.c:345: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:361: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:377: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:393: undefined reference to `check_toughness'
obj/mage.o:tbw/reloaded/src/mage.c:409: more undefined references to `check_toughness' follow
obj/update.o: In function `mobile_update':
tbw/reloaded/src/update.c:756: undefined reference to `werewolf_regen'
obj/powerl.o: In function `do_planarstorm':
tbw/reloaded/src/powerl.c:680: undefined reference to `check_toughness'
collect2: error: ld returned 1 exit status
Makefile:27: recipe for target '../src/reloaded' failed
make: *** [../src/reloaded] Error 1
The codebase and the referenced files are huge, so I figured it wouldn't make sense to attach them just yet, but if required I can definitely provide them.
For the record, those functions like "check_toughness" and "xp_compute" are definitely defined within those files after a few thousand LOC.
Would appreciate any suggestions, thank you!
Thank you to everyone who came in with suggestions!
The simplest answer was provided by rici:
That is probably the result of the code using the old idiosyncratic gcc semantics for inline. Try compiling with --std=gnu89 (if you are using gcc).
Adding that to the Makefile cleared up all the errors and resulted in a successful compile.

Microchip problem with usb_device.c file, getting errors i cannot solve

Well the problem is these errors
I have not touched these files but just downloaded the legacy mla and used the files. So I'm assuming there is a problem with my directories in some way.
I have the path to the microchip/include file and some of the code works. So now when im building the project i encounter these problems. I've tried changing the paths, using linker folders but nothing seems to work.
I know the the functions are in the usb_device_local.h file and its included but still nothing
im using mplabx v5.15, and xc32 compiler v2.15. Also a older pic32mx
build/default/production/_ext/2021492214/usb_device.o: In function `_USB1Interrupt':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:887: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:937: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:995: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBStdSetCfgHandler':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2180: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBStdGetDscHandler':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2218: undefined reference to `device_dsc'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2218: undefined reference to `device_dsc'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2226: undefined reference to `USB_CD_Ptr'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2226: undefined reference to `USB_CD_Ptr'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2242: undefined reference to `USB_SD_Ptr'
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2242: undefined reference to `USB_SD_Ptr'
build/default/production/_ext/2021492214/usb_device.o: In function `USBSuspend':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2437: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBWakeFromSuspend':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2463: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBCtrlTrfSetupHandler':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2657: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBCheckStdRequest':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:2879: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o: In function `USBStdFeatureReqHandler':
c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:3041: undefined reference to `USER_USB_CALLBACK_EVENT_HANDLER'
build/default/production/_ext/2021492214/usb_device.o:c:/microchip_solutions_v2013-06-15/microchip/usb/usb_device.c:3071: more undefined references to `USER_USB_CALLBACK_EVENT_HANDLER' follow
collect2.exe: error: ld returned 255 exit status
Looking at the compiler you are using and the date that this tutorial was made leads me to believe that the some of the tutorial is not only out of date but the the main/interrupt code will be incompatible with the type of PIC and compiler you are using. (So even if you could get rid of these errors you'd just get more unless you know what you are doing!)
However, if you have followed the tutorial correctly and added the HardwareProfile.h, usb_device.c, usb_descriptors.c and main.c files from the tutorial (except the interrupt and #config stuff in main.c as they will be incompatible with the PIC32), it should build successfully albeit with a bunch of unrelated PLIB warnings.
The file structure should be like this below:
usb_descriptors.c, main.c, HardwareProfile.h, usb_config.h should all be your own created .c files via New --> C Source File to your project and adding the code from the tutorial. These should then exist in your project folder.
Whereas usb_device.c and usb_function_cdc.c should be from the microchip mla folder
As the tutorial states, albeit not very clearly, you must set the include directories correctly.
To do this go to Project Options then:
xc32 (Global Options) --> Common include dirs
set the following:
(Whereever MLA is installed , mine is probably a different version)
And do the same for
xc32-as General --> Preprocessor Include directories and
xc32-as General --> Assembler Include directories
Microchip recommends on their website 32-bit PIC32 customers (except for PIC32MM) should use MPLAB Harmony Integrated Software Framework which includes TCPIP, USB, Graphics, File systems and more. If you are using PICMM then I'd recommend the latest version of MLA, not 2013 version, you can find on the Microchip MLA page. If not I'd recommend learning their harmony plugin.

undefined reference to '__imp_fmi2_import_free'

I have been trying to compile and link a test file written in c and which can communicate with FMILibrary of JModelica. I was able to compile and link it and run it in linux systems. coming to the Windows, I am using mingw-64 compiler to compile and link the test file with FMILibrary, but I am getting undefined reference errors. I was able to compile and run it on 32 bit mingw but I need to compile and link it with 64 bit compiled binaries.
My command goes like this:
gcc -I <..fmilib\include> -L <..fmilib\lib> -lfmilib -o testfile testfile.c fmivars.c
And the following is the result that is getting printed out as a result
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x9b): undefined reference to `__imp_fmi2_import_get_real'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0xd6): undefined reference to `__imp_fmi2_import_get_integer'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x111): undefined reference to `__imp_fmi2_import_get_boolean'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x14c): undefined reference to `__imp_fmi2_import_get_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x187): undefined reference to `__imp_fmi2_import_set_real'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x1c2): undefined reference to `__imp_fmi2_import_set_integer'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x1fd): undefined reference to `__imp_fmi2_import_set_boolean'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x238): undefined reference to `__imp_fmi2_import_set_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x27a): undefined reference to `__imp_fmi2_import_new_discrete_states'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x2b6): undefined reference to `__imp_fmi2_import_collect_model_counts'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x30b): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x37e): undefined reference to `__imp_jm_vsnprintf'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x395): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x437): undefined reference to `__imp_jm_vsnprintf'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x556): undefined reference to `__imp_fmi2_import_get_version'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x575): undefined reference to `__imp_fmi2_import_get_types_platform'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x594): undefined reference to `__imp_fmi2_import_get_number_of_continuous_states'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x5a8): undefined reference to `__imp_fmi2_import_get_number_of_event_indicators'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x64a): undefined reference to `__imp_fmi2_import_instantiate'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x690): undefined reference to `__imp_fmi2_import_set_debug_logging'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x6af): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x6df): undefined reference to `__imp_fmi2_import_set_debug_logging'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x718): undefined reference to `__imp_fmi2_import_setup_experiment'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x733): undefined reference to `__imp_fmi2_import_enter_initialization_mode'
Is there any macro or anything set on the FMILibrary to compile with 64 bit mingw compiler on windows 64 bit? Thanks.
Assuming the library libfmilib.x.y.z provided the missing symbols then on the linker's/compiler's command line move it to the right of the .c-files requiring them
gcc -I <..fmilib\include> -L <..fmilib\lib> -o testfile testfile.c fmivars.c -lfmilib
Thank you everyone for helping me. I finally solved my problem and was able to run the code. I installed dependency walker as suggested by #PilouPili and found out that my application is looking for the library in the same folder(I don't know for some reason) and it was unable to find it. So, I copied all the static and dynamic libraries and I pasted in the folder where my testfile is. Also I changed the command line as suggested by #alk and moved the -lfmilib to the end. And I used the dynamic library instead of static one. But anyways my application runs now. Thank you so much for helping out.

Undefined reference to the function 'check' (GCC compilation in MinGW)

I seem to be getting the rookie error where it says, undefined reference to 'check', as shown below:
This should not be a problem, as I have in fact made a check.h and included in hiker.c, as shown below:
Does anybody know the source of this problem? I have just started using MinGW(as I wanted to learn programming C on Windows).
Here is a picture of the main function. I can add the code too if necessary:
I guess that check function is implemented in a file check.c
You must link that file also, because of your check.h export the prototype to let the compiler know how the check function is structured, but the linker needs the check function code compiled and reachable.
What you need is to compile using a command like this:
gcc -Wall hiker.c check.c -o hiker.exe
Take also note that linker is giving you another error about WinMain#16
This means that you started a windows application project, I guess you must change your project to console project type.

Cannot compile program on Ubuntu that uses libmcrypt

I created a C program that uses libmcrypt. I compiled it for many times in a CentOS machine, but now, trying to do the same thing in Ubuntu, I get this:
/tmp/ccM2ugbq.o: In function `encrypt':
util.c:(.text+0xa1): undefined reference to `mcrypt_module_open'
util.c:(.text+0xc6): undefined reference to `mcrypt_enc_get_iv_size'
util.c:(.text+0x134): undefined reference to `mcrypt_generic_init'
util.c:(.text+0x1dc): undefined reference to `mcrypt_generic'
util.c:(.text+0x1fa): undefined reference to `mcrypt_module_close'
/tmp/ccM2ugbq.o: In function `decrypt':
util.c:(.text+0x288): undefined reference to `mcrypt_module_open'
util.c:(.text+0x296): undefined reference to `mcrypt_enc_get_iv_size'
util.c:(.text+0x304): undefined reference to `mcrypt_generic_init'
util.c:(.text+0x375): undefined reference to `mdecrypt_generic'
util.c:(.text+0x380): undefined reference to `mcrypt_module_close'
, although I have installed libmcrypt and have spacified the flags properly when compile (-I/usr/include -L/usr/lib -lmcrypt)
Can anyone guide me on how to get the compilation work properly with libmcrypt?
EDIT: man pages says: Compile as "cc prog.c -lmcrypt", or "cc prog.c -lmcrypt -lltdl" depending on your installation.
I also installed libltdl-dev, but it does not work.
EDIT 1:
System information:
version (running uname -r):
3.5.0-25-generic
release (running lsb_release -a):
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.10
Release: 12.10
Codename: quantal
EDIT 2:
Because #teppic requested me to show the compile command, I solved my issue, but I need some explanations. Bellow I'll detail the topic:
the command that I used and failed:
cc -Wall -I../path/to/include -lmcrypt ./a_file.c ./some/other/file.c ./some/other/files.c ./main/file.c -I/some/include/path -lother_lib -o ./bin/out
After that, I only put the -lmcrypt at the end of command and deleted it from the first place, and it worked.
In my initial question, I told you that I did compile it before in CentOS and everything worked fine. That's true, even if in CentOS the compile command were the former one (probably some files differ in order or some libraries).
Can anybody explain me how the flags order influences the compilation success or failure?
In general you should put the library dependency after the source file that references it in the command line. In older versions of gcc, this wasn't always the case.
1) Try installing libmrypt-dev
2) Locate the path of libmcrypt using "locate" command
3) If not in standard library path, try adding the path to LD_LIBRARY_PATH environment variable
4) If nothing helps try installing again using "yum install mcrypt-devel"

Resources