SQLite: trouble building FTS5 loadable extension - c

I'm on Mac trying to build FTS5 as loadable extension.
I've downloaded the SQLite sources, successfully executed ./configure and make fts5, obtained fts5.{c,h} files.
Now when trying to build the dynamic library for the extension I get:
gcc -g -fPIC -dynamiclib -o fts5.dylib fts5.c
In file included from fts5Int.h:18:0:
fts5_storage.c: In function 'sqlite3Fts5StorageOpen':
fts5_storage.c:305:9: error: 'sqlite3_api_routines' has no member named '__builtin___snprintf_chk'
In file included from /usr/include/secure/_string.h:33:0,
from /usr/include/string.h:192,
from fts5Int.h:21:
fts5_storage.c:305:26: warning: passing argument 1 of '__builtin_object_size' makes pointer from integer without a cast
fts5_storage.c:305:26: note: expected 'const void *' but argument is of type 'int'
In file included from fts5Int.h:18:0:
fts5_storage.c:308:11: error: 'sqlite3_api_routines' has no member named '__builtin___snprintf_chk'
In file included from /usr/include/secure/_string.h:33:0,
from /usr/include/string.h:192,
from fts5Int.h:21:
fts5_storage.c:308:28: warning: passing argument 1 of '__builtin_object_size' makes pointer from integer without a cast
fts5_storage.c:308:28: note: expected 'const void *' but argument is of type 'int'
What am I doing wrong?
I've tried gcc 4.9 and 5.5 from MacPorts on macOS
Interesting enough, on Linux (and with gcc5) I'm getting this error:
❯ gcc -g -fPIC -shared -o fts5.so fts5.c
fts5.h:24:21: fatal error: sqlite3.h: No such file or directory
compilation terminated.
And sure enough there's no sqlite3.h in the root of the sources directory, though I expect it should be created during the make step?
I can of course install libsqlite3-dev but I already have all the sqlite sources, why should I?

Thanks to Dan Kennedy from the SQLite dev team the issue is now resolved.
The 1st issue appeared to be the actual problem with SQLite source code when compiled on macOS, and it's now fixed here: http://www.sqlite.org/src/info/cd0471ca9f75e7c8
The 2nd problem was about the header file not generated because it requires a separate make step. So the full build instructions actually look like this:
./configure
make fts5.c sqlite3.h sqlite3ext.h
gcc -O2 -fPIC -shared fts5.c -o fts5.dylib

Related

Linking EFI application with LLVM on MacOS

I'm attempting to cross-compile and link a very simple EFI application that is using the EFI headers from the Zircon kernel. Despite my best efforts, I am unable to link a working PE executable under macOS Montery (with apple silicon), due to the LLD flag -subsystem:efi_application not being valid. The full error is:
FAILED: test.efi: && /opt/local/bin/clang -target x86_64-none-elf -ffreestanding -nostdlib -fuse-ld=lld -dll -WX -Wl,-subsystem:efi_application -Wl,entry:efi_main src/main.c.obj -o test.efi && :
ld.lld: error: unknown argument '-subsystem:efi_application'
Several guides indicate that lld-link is required to compile this correctly, however adding -fuse-ld=lld-link results in errors stating:
clang: error: invalid linker name in argument '-fuse-ld=lld-link'
This occurs despite the fact that I have lld-link in my $PATH. If I, instead, pass the full lld-link path to -fuse-ld=, I get the following error:
FAILED: test.efi: && /opt/local/bin/clang -target x86_64-none-elf -ffreestanding -target x86_64-none-elf -nostdlib -dll -WX -Wl,-subsystem:efi_application -Wl,-entry:efi_main -fuse-ld=/opt/local/bin/lld-link src/main.c.obj -o test.efi && :
lld-link: warning: ignoring unknown argument '--eh-frame-hdr'
lld-link: warning: ignoring unknown argument '-m'
lld-link: warning: ignoring unknown argument '-dynamic-linker'
lld-link: warning: ignoring unknown argument '-o'
lld-link: warning: ignoring unknown argument '-L/opt/local/libexec/llvm-13/bin/../lib'
lld-link: warning: ignoring unknown argument '-L/usr/lib'
lld-link: error: could not open 'elf_x86_64': No such file or directory
lld-link: error: could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
lld-link: error: could not open 'test.efi': No such file or directory
lld-link: error: src/main.c.obj: unknown file type
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am using the MacPorts LLVM-13 package. The result of $ lld-link --version is LLD 13.0.0.
For reference, the code I'm attempting to compile and link is, simply:
#include "efi/protocol/graphics-output.h"
#include "efi/protocol/loaded-image.h"
#include "efi/system-table.h"
#include "efi/types.h"
#define ERR(x) if (EFI_ERROR((x))) { return (x); }
efi_status efi_main(efi_handle handle __attribute__((unused)), efi_system_table* st) {
efi_status status;
/* clear the screen */
status = st->ConOut->ClearScreen(st->ConOut);
ERR(status);
/* print 'Hello World' */
status = st->ConOut->OutputString(st->ConOut, u"Hello World");
ERR(status);
return EFI_SUCCESS;
}
What do I need to change above in order to build an EFI application using LLVM on macOS?
I'd also be curious to know any ideas as to why -fuse-ld=lld-link would fail when it exists in my PATH, and why using -fuse-ld=/opt/local/bin/lld-link would result in other implicit linker flags not succeeding.
System Details:
Compiler Suite: LLVM-13 (Macport Installation)
Host OS: macOS Monterey (Apple Silicon, M1 Pro)
Target Arch: x86_64
Build System: CMake using custom toolchain (which passes the -nostdlib, -target ... args, etc.)
You can try to use clang-cl to compile your code, using /c option to compile only: do not link yet. Use /Fo option to specify the output object file.
The clang-cl offers compatibility options from MSVC cl.exe. For further details, run clang-cl --help. The build target of clang-cl is default to windows, so you don't have to reset the build target in order to compile for EFI applications.
Be warned that clang-cl does not have full support to MSVC intrinsics. Intrinsics like __vmx_vmptrld, __svm_vmload, etc. are broken. clang-cl would generate a call instruction rather than the specific instruction. Define them in inline assembly in GCC's syntax, if you want to use these intrinsics.
After you compiled all source files into object files, run lld-link to link all output object files with /SUBSYSTEM:EFI_APPLICATION parameter into an EFI application.
I haven't used the header files from Zircon yet, but I tried compiling EDK II libraries with LLVM into .lib files on Windows.
With the help of these .lib files, I made some simple EFI applications. For instance, you can check this partition enumerator out.
The batch scripts might not work on MacOS, but, by reading them, you can definitely figure out the general ideas about how to specify the parameters.
If you want to use EDK II by virtue of its rich libraries, you might want to install Netwide Assembler as well, in that the assembly codes in EDK II libraries are NASM.

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.

Weird flags when building LLVM project with Make using the Clang Compiler

I recently built LLVM into the following path: C:\LLVM\llvm-new-build. I then added this path to my Environmental Variables/Path, C:\LLVM\llvm-new-build\Debug\bin. I'm trying to build my LLVM project, but I'm getting some weird output from Clang:
clang `llvm-config --cflags` -Wall -Iincludes/ src/*.c -c src/*.c
clang.exe: error: unknown argument: '-wd4146'
clang.exe: error: unknown argument: '-wd4180'
clang.exe: error: unknown argument: '-wd4244'
clang.exe: error: unknown argument: '-wd4258'
clang.exe: error: unknown argument: '-wd4267'
clang.exe: error: unknown argument: '-wd4291'
clang.exe: error: unknown argument: '-wd4345'
clang.exe: error: unknown argument: '-wd4351'
clang.exe: error: unknown argument: '-wd4355'
clang.exe: error: unknown argument: '-wd4456'
clang.exe: error: unknown argument: '-wd4457'
clang.exe: error: unknown argument: '-wd4458'
clang.exe: error: unknown argument: '-wd4459'
clang.exe: error: unknown argument: '-wd4503'
clang.exe: error: unknown argument: '-wd4624'
clang.exe: error: unknown argument: '-wd4722'
clang.exe: error: unknown argument: '-wd4800'
clang.exe: error: unknown argument: '-w14062'
clang.exe: error: unknown argument: '-we4238'
clang.exe: error: no such file or directory: 'C:/Program Files (x86)/Git/DWIN32'
clang.exe: error: no such file or directory: 'C:/Program Files (x86)/Git/D_WINDO
WS'
clang.exe: error: no such file or directory: 'C:/Program Files (x86)/Git/W3'
clang.exe: error: no such file or directory: 'C:/Program Files (x86)/Git/MP'
Makefile:22: recipe for target 'all' failed
make: *** [all] Error 1
It says there are no arguments like -wd4146 etc, but I haven't passed those to the clang compiler, and a quick google search shows know helpful answers on what these mean. This is what my build file looks like:
LCC = clang
LCXX = clang++
LLVM_CC_FLAGS=`llvm-config --cflags`
LLVM_LINK_FLAGS=`llvm-config --libs --cflags --ldflags core analysis executionengine jit interpreter native`
C_FLAGS = -Wall -Iincludes/
CXX_FLAGS = -Wall -Wextra -Wno-self-assign
SOURCES = src/*.c
all: ${SOURCES}
${LCC} ${LLVM_CC_FLAGS} ${C_FLAGS} ${SOURCES} -c ${SOURCES}
${LCXX} ${LLVM_LINK_FLAGS} *.o ${LLVM_FLAGS} -o j4
-rm *.o
The output from llvm-config --cflags
-IC:/LLVM/llvm/include -IC:/LLVM/llvm-new-build/include /DWIN32 /D_WINDOWS /W3
/MP -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEP
RECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WA
RNINGS -wd4146 -wd4180 -wd4244 -wd4258 -wd4267 -wd4291 -wd4345 -wd4351 -wd4355 -
wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4800 -w14062 -we4238 -
D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
This question really has several layers, so I'm going to try to break this down into three parts: a discussion of what is happening inside the backticks, the unknown argument errors, and the no such file or directory errors.
What is llvm-config?
llvm-config is a tool for the LLVM infrastructure that gets configuration information needed to compile programs that need LLVM. So in response to the comment at 1, llvm-config actually is intended for use with clang when clang is used to compile an LLVM project.
The --cflags option gives C compiler flags including LLVM headers, which you saw in the output to llvm-config --cflags. You said
"It says there are no arguments like -wd4146 etc, but I haven't passed those to the clang compiler"
But by putting it in backticks, your shell took the output from llvm-config --cflags and pasted it into your original command. So you did include those arguments, you just didn't realize it!
I will also note that the output from llvm-config is highly dependent on your build system and the version of LLVM. For example, when installed on Ubuntu Linux 14.05, LLVM 3.5 with GNU Make and Ninja generators, the output from llvm-config --cflags is:
-I/.../llvm-3.5.0/llvm/include -I/.../llvm-3.5.0/build/include -fPIC -Wall -W -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-comment -ffunction-sections -fdata-sections -g -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
It noticeably doesn't include any of your offending options like -wd4146 or -wd4180 nor any reference to Windows or preprocessor arguments.
What are those weird options like /DWIN32, /D_WINDOWS, /W3, and /MP?
/D defines a preprocessing symbol for a source file, in this case WIN32 and _WINDOWS. 2
/W3 directs MSVC to display level 1, level 2 and level 3 (production quality) warnings. 3
/MP causes MSVC to create multiple instances of itself and attempt to build the project in parallel. 4
The problem is that they're passed to the compiler's arguments prefixed with a forward slash (notice that all other options were passed with a hyphen). As a result, your build is attempting to handle those as file names, as indicated by the resulting errors, for example:
clang.exe: error: no such file or directory: 'C:/Program Files (x86)/Git/DWIN32'
Why it's looking in C:/Program Files (x86)/... is up to some aspect of your LLVM installation and/or your operating system. I'm going to guess it's the last location in your execution path or it is your present working directory.
What are those weird options like -wd4146 and -wd4180?
Those are options to disable certain warnings emitted for MSVC. For example, C4146 is "unary minus operator applied to unsigned type, result still unsigned" and C4180 is "qualifier applied to function type has no meaning; ignored"
Here's an example of doing the exact same thing, but from inside a GNU Make file instead of from the command line (look at the block beginning if (MSVC))
So why isn't my project building?
I can't answer this authoritatively without inspecting your LLVM build. However,
Unknown argument: You've discovered an incompatibility between your version of llvm-config and clang. You noted that you added C:\LLVM\llvm-new-build\Debug\bin to your path, but that doesn't assure that the binary actually executed for each of llvm-config and clang came from the same location. If you had previously installed a canonical, pre-built binary of clang for generic compilation usage, its location will be earlier in your path than C:\LLVM\llvm-new-build\Debug\bin. It's unlikely that llvm-config was included in your pre-built binaries. The reason this matters is that if there's a mismatch between versions, the required include flags generated by llvm-config might not match the required include flags needed by clang. You can verify that execution path shadowing is not happening using which on Unix-like machines and where.exe on Windows machines after Windows Server 2003. We expect that they will both reflect that the execution path is in fact C:\LLVM\llvm-new-build\Debug\bin. If not, there's your problem. I believe that this is what created the issues with options like -wd4146 and -wd4180, etc.
No such file or directory: When you built LLVM, cmake detected you were building on Windows, and produced Visual Studio generator files. Meanwhile, your project appears to use some sort of GNU Make-like build system. See here for more discussion of selecting generators at installation. I believe that the mix between MSVC and another GNU Make-like build system is what created the issues with options like /DWIN32, /D_WINDOWS, /W3, and /MP.

How to compile an example SDL program written in C?

I'm getting started with SDL and C programming. I have experience with other programming languages, but linking/compiling libraries in C is new to me. I am using Mac 10.8 and have installed latest stable 2.0 using the instructions in the read me (./configure; make; make install). Here is the sample code that I am trying to compile:
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
int main(void)
{
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) {
fprintf(stderr, "\nUnable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
return 0;
}
When I try to compile my script using gcc example.c, I get an error:
example.c:3:17: error: SDL.h: No such file or directory
example.c: In function ‘main’:
example.c:7: error: ‘SDL_INIT_VIDEO’ undeclared (first use in this function)
example.c:7: error: (Each undeclared identifier is reported only once
example.c:7: error: for each function it appears in.)
example.c:7: error: ‘SDL_INIT_TIMER’ undeclared (first use in this function)
example.c:8: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
example.c:8: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
example.c:11: error: ‘SDL_Quit’ undeclared (first use in this function)
I tried searching the wiki, and tutorials, and any kind of documentation that I could find, but I could not find any example anywhere that showed how to properly compile a C program that uses SDL.
What do I need to do to compile this program?
A general hint for C beginners: read error logs top-down: often fixing first error will resolve all other. In your case first error is:
example.c:3:17: error: SDL.h: No such file or directory
As others have said, you need to instruct gcc where to find SDL.h. You can do this by providing -I option.
To check where SDL.h is installed by default I would issue
./configure --help
in the directory where you did build libsdl. Then look for --prefix, under Linux default prefix is often /usr/local. To compile your example I would issue (on Linux):
gcc example.c -I/usr/local/include
But the above command compiles and links the code. After successful compilation, gcc would throw another bunch of errors, one of them being undefined reference.
To prevent that, full command line to build your example (on Linux at least) would be:
gcc example.c -I/usr/local/include -L/usr/local/lib -lSDL
Where:
-I points compiler to directory with SDL.h,
-L points linker to directory with libSDL.a (or libSDL.so),
-l instructs linker to link with library, in our case libSDL.a or libSDL.so. Note that the lib prefix and .a/.so suffix is missing.
Please note that I didn't check this instruction, even on Linux machine (on the other hand I have no access to Mac OS machine).
One more thing: by default binary with the compiled and linked example will be called a.out. To change that you can provide -o option to gcc.
I found out you can use a tool called pkg-config to find out the compiler flags expected for a specific library.
$ pkg-config --cflags --libs sdl2
-D_THREAD_SAFE -I/usr/local/include/SDL2 -I/usr/X11R6/include -L/usr/local/lib -lSDL2
$ gcc example.c $(pkg-config --cflags --libs sdl2)
If you are using a Makefile, you need to prefix the command with shell:
all:
gcc example.c $(shell pkg-config --cflags --libs sdl2)
tl;dr
sudo apt install libsdl1.2-dev
You are missing the SDL library files. Just instal them and everything should work out of the box.
Different versions ans extensions
There are multiple versions of SDL, make sure you install the one that is required by your application. There are also additional libraries (called projects) for SDL that you also need to install if you use their features. For example if you use TTF fonts or image related functionalities. Just press TAB twice after you typed in sudo apt install libsdl to see all the available packages.

Undefined reference errors in gcc when compiling on another machine

I wrote a program (myreader.c) to manipulate a RFID reader.
I compile by type "make" in the root of the package, makefile is shown below
# CC and CFLAGS are varilables
CC=gcc
CFLAGS = -c
# -c option ask g++ to compile the source files, but do not link.
# -g option is for debugging version
# -O2 option is for optimized version
OPTFLAGS = -O2 -g
myreader : src/myreader.c
$(CC) $(OPTFLAGS) src/myreader.c src/crypto1.c src/nfc-utils.c -lnfc -o ./bin/myreader
# clean all the .o and executable files
clean:
rm -rf bin/myreader
and it works well on my original machine(64 bits, Ubuntu 12.04 LTS), and the only problem is, when I type make, the warning info would come up.
src/myreader.c:519:6: warning: conflicting types for ‘printResult’ [enabled by default]
src/myreader.c:211:3: note: previous implicit declaration of ‘printResult’ was here
But /bin/myreader works well.
However, when I move the package to another machine(64 bits, Ubuntu 11.10), and type make in the same way as in the original machine.
Error messages in the below appears:
berln#ubuntu:~/桌面/useful code$ make
gcc -O2 -g src/myreader.c src/crypto1.c src/nfc-utils.c -lnfc -o ./bin/myreader
src/myreader.c:519:6: warning: conflicting types for ‘printResult’ [enabled by default]
src/myreader.c:211:3: note: previous implicit declaration of ‘printResult’ was here
/tmp/ccrKvhjm.o: In function `mf_enhanced_auth':/home/berln/桌面/useful code/src/myreader.c:373: undefined reference to `nfc_configure'
/home/berln/桌面/useful code/src/myreader.c:380: undefined reference to `nfc_configure'
/home/berln/桌面/useful code/src/myreader.c:390: undefined reference to `nfc_configure'
/home/berln/桌面/useful code/src/myreader.c:434: undefined reference to `nfc_configure'
/tmp/ccrKvhjm.o: In function `mf_configure':
/home/berln/桌面/useful code/src/myreader.c:484: undefined reference to `nfc_configure'
/tmp/ccrKvhjm.o:/home/berln/桌面/useful code/src/myreader.c:489: more undefined references to `nfc_configure' follow
/tmp/ccrKvhjm.o: In function `main':
/home/berln/桌面/useful code/src/myreader.c:155: undefined reference to `nfc_connect'
/home/berln/桌面/useful code/src/myreader.c:213: undefined reference to `nfc_disconnect'
collect2: ld returned 1 exit status
make: *** [myreader] Error 1
I have no ideas why this error happened on only one machine instead of both.
If you need more information, you can download the package here.
Thanks in advance.
It seems the problem is in the nfc library, but the linker doesn't complain that it's missing, so something wrong with it. Try to recompile it. If it's a package check that it's the same version as on the other server.
Most likely your nfc library is missing or not installed properly on your other computer.
One of the options you pass to the linker is -lnfc, which tells it to link to the nfc library. Your errors are coming from the linker, which cannot find the nfc_configure and other nfc_ symbols. This means that the linker cannot find these symbols. Check the nfc library installation.

Resources