Clang compiler ignoring the .a library file - c

This compiling works OK:
$ clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -l:libconfuse.so main.cpp
This one does not (undefined references on internal functions):
$ clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -l:libconfuse.a main.cpp
/tmp/main-115bc4.o: En la función `main':
main.cpp:(.text+0x691): referencia a `cfg_init' sin definir
main.cpp:(.text+0x6ab): referencia a `cfg_parse' sin definir
main.cpp:(.text+0x6da): referencia a `cfg_getstr' sin definir
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Same error with these command lines:
$ clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -L/opt/cross-freebsd-10/usr/lib/ -l:libconfuse.a main.cpp
$ clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -L/opt/cross-freebsd-10/usr/lib/ -l:libconfuse.a -static main.cpp
The files for the LibConfuse C programming library seem to be at the correct path:
$ ls -la /opt/cross-freebsd-10/usr/lib/libconfuse*
-rwxrwxrwx 1 luis luis 78318 sep 29 2018 /opt/cross-freebsd-10/usr/lib/libconfuse.a
lrwxrwxrwx 1 luis luis 19 sep 29 2018 /opt/cross-freebsd-10/usr/lib/libconfuse.so -> libconfuse.so.2.0.0
lrwxrwxrwx 1 luis luis 19 sep 29 2018 /opt/cross-freebsd-10/usr/lib/libconfuse.so.2 -> libconfuse.so.2.0.0
-rwxr-xr-x 1 luis luis 56616 sep 29 2018 /opt/cross-freebsd-10/usr/lib/libconfuse.so.2.0.0
So, I would say the compiler can not see the .a file. Am I right? How could I solve it?
I need to solve this because I am trying to compile with static linking for the LibConfuse library, as long as I don't need to install that package on destination computers. So, as I have read, the .a library file must be used.
Further Data:
Note that I am cross-compiling to FreeBSD. I don't know if that matters.
When running (on a remote FreeBSD computer) the executable generated by the .so mode above, the program yields «Shared object "libconfuse.so.2" not found, required by [MyExecutableName]». This is why I am trying to perform static link.
Tests performed on Ubuntu Linux v16.04.
New data upon requestion:
Same first line that works OK, but with -### parameter to show extra info:
1$ clang -### -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -l:libconfuse.so main.cpp
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-unknown-freebsd10.0
Thread model: posix
InstalledDir: /usr/bin
"/usr/lib/llvm-3.8/bin/clang" "-cc1" "-triple" "x86_64-unknown-freebsd10.0" "-emit-obj" "-mrelax-all" "-disable-free" "-disable-llvm-verifier" "-main-file-name" "main.cpp" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0" "-isysroot" "/opt/cross-freebsd-10/" "-internal-isystem" "/opt/cross-freebsd-10//usr/include/c++/v1" "-fdeprecated-macro" "-fdebug-compilation-dir" "/media/Almacen01/Temporal/CPlusPlus/PruebaCSV01" "-ferror-limit" "19" "-fmessage-length" "83" "-fobjc-runtime=gnustep" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/tmp/main-065e9b.o" "-x" "c++" "main.cpp"
"/usr/bin/ld" "--sysroot=/opt/cross-freebsd-10/" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld-elf.so.1" "--hash-style=both" "--enable-new-dtags" "-o" "a.out" "/opt/cross-freebsd-10//usr/lib/crt1.o" "/opt/cross-freebsd-10//usr/lib/crti.o" "/opt/cross-freebsd-10//usr/lib/crtbegin.o" "-L/opt/cross-freebsd-10//usr/lib" "-l:libconfuse.so" "/tmp/main-065e9b.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/opt/cross-freebsd-10//usr/lib/crtend.o" "/opt/cross-freebsd-10//usr/lib/crtn.o"
More data requested by Ahmed:
$ clang -### -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ /opt/cross-freebsd-10/usr/lib/libconfuse.a main.o -o LogManager
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-unknown-freebsd10.0
Thread model: posix
InstalledDir: /usr/bin
"/usr/bin/ld" "--sysroot=/opt/cross-freebsd-10/" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld-elf.so.1" "--hash-style=both" "--enable-new-dtags" "-o" "LogManager" "/opt/cross-freebsd-10//usr/lib/crt1.o" "/opt/cross-freebsd-10//usr/lib/crti.o" "/opt/cross-freebsd-10//usr/lib/crtbegin.o" "-L/opt/cross-freebsd-10//usr/lib" "/opt/cross-freebsd-10/usr/lib/libconfuse.a" "main.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/opt/cross-freebsd-10//usr/lib/crtend.o" "/opt/cross-freebsd-10//usr/lib/crtn.o"

Change the commandline to:
clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -c main.cpp -o main.o
clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ /opt/cross-freebsd-10/usr/lib/libconfuse.a main.o -o main
This will allow you to link the libconfuse.a right into the binary with static symbols. Let me know if you run into trouble

If you want to link to the library file libconfuse.a then you can do that by specifying only the filename (without the -l: part), or you can write -lconfuse (the lib and .a parts are then assumed. Writing -l:libconfuse.a will not work, I think.

Related

CLion filesystem linker problem even with -lstdc++fs

I've tried to use <filesystem> in my CLion project on Fedora 29 environment.
When compiling directly from terminal it works smoothly, but when i try to compile from CLion there is a Linker issue about filesystem. I'm not shure what else I can do. Any suggestions?
g++ (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2)
clang version 7.0.1
(Fedora 7.0.1-6.fc29)
Here is what i have already tried:
I've added the flag -lstdc++fs:
set(CMAKE_CXX_FLAGS -lstdc++fs)
but i didn't worked. I've verified if this flag is in use by:
set( CMAKE_VERBOSE_MAKEFILE on )
and it seems it is:
[ 50%] Building CXX object CMakeFiles/untitled.dir/main.cpp.o
/usr/bin/g++ -lstdc++fs -g -std=gnu++17 -o
CMakeFiles/untitled.dir/main.cpp.o -c
/home/patryk/CLionProjects/untitled/main.cpp
[100%] Linking CXX executable untitled
/home/patryk/clion-2018.3.4/bin/cmake/linux/bin/cmake -E
cmake_link_script CMakeFiles/untitled.dir/link.txt --verbose=1
/usr/bin/g++ -lstdc++fs -g CMakeFiles/untitled.dir/main.cpp.o -o
untitled
/usr/bin/ld: CMakeFiles/untitled.dir/main.cpp.o: in function
`std::filesystem::__cxx11::path::path<char [2],
std::filesystem::__cxx11::path>(char const (&) [2],
std::filesystem::__cxx11::path::format)':
/usr/include/c++/8/bits/fs_path.h:184: undefined reference to
`std::filesystem::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status
I've tried also to use clang compiler with exact same results.
main.cpp
#include <iostream>
#include <filesystem>
int main() {
std::filesystem::path p("D");
return 0;
}
CMake use target_link_libraries to add -l linker flags.
target_link_libraries(your_executable stdc++fs)
Why set(CMAKE_CXX_FLAGS -lstdc++fs) not working: -l option must be set after your source or object file.
c++ -lstdc++fs some_object.o -o executable # not working
c++ some_object.o -o executable -lstdc++fs # should work

'stdio.h' File Not Found When Compiling Hello World

Edit: added output of $cc -v main.c at the end of this post.
I'm using an old Xcode because my kernel extension will support El Capitan. That works with 8.3 by copying the 10.11 SDK from an older Xcode build.
#include <stdio.h> // 'stdio.h' file not found
int main( int argc, char **argv )
{
printf( "Hello World!\n" );
return 0;
}
$ ls -l /usr/include/stdio.h
-r--r--r-- 1 root wheel 19154 Feb 4 2017 /usr/include/stdio.h
$ ls -l /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/stdio.h
-r--r--r-- 7 mike staff 19154 Feb 3 2017 /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/stdio.h
I'm trying to build a userspace command line tool to test my kernel extension.
This is a moderately common problem but none of the solutions I've tried so far have worked. There are lots of reports of it happening in Visual Studio, not just Xcode.
Just now I reinstalled the Command Line Tools. I changed the SDK from "latest macOS" to "macOS 10.12".
The source file is called "main.c" - that is, not "main.cpp".
$ cc -v main.c
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 278.4 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0 -fdebug-compilation-dir /Users/mike/Projects/RCI/trunk/HD1/ButtonTest -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/xc/jc2d96hx25l9ntd2vgnh124m0000gn/T/main-7206a2.o -x c main.c
clang -cc1 version 8.1.0 (clang-802.0.42) default target x86_64-apple-darwin16.7.0
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/include
/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library
/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.12.0 -o a.out
/var/folders/xc/jc2d96hx25l9ntd2vgnh124m0000gn/T/main-7206a2.o -lSystem
/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/lib/darwin/libclang_rt.osx.a
I Should Not Drink And Code:
My project had at first just one target, for a kernel extension. Later I added a second target for a command-line tool.
When I created a new source file for my command-line tool that source somehow got added to the kernel extension's target. Changing the tool's header search path settings had no effect on my problem because the source was not in the tool's target.
Kernel Extensions - device drivers - have headers that are only from Kernel.framework, in which there is no stdio.h file.
I'll shut up now.

How can I compile mysql-connector-c for macOS 10.13.x using C?

Synopsis
I have a small c program, it's a standard "hello world" application to test I can access the mysql connection driver accordingly:
#include <stdio.h>
#include "mysql.h"
int main(int argc, const char **argv)
{
printf("MySQL client version: %s\n", mysql_get_client_info());
return 0;
}
When I compile this using the following; I get an error:
gcc src/main.c \
-Wall \
-Ilib/mysql-connector-c-6.1.11-macos10.12-x86_64/include \
-o bin/test
Undefined symbols for architecture x86_64:
"_mysql_get_client_info", referenced from:
_main in main-59d4fb.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have then attempted to link mysql with the following:
gcc src/main.c \
-Wall \
-Ilib/mysql-connector-c-6.1.11-macos10.12-x86_64/include \
-Llib/mysql-connector-c-6.1.11-macos10.12-x86_64/mysql-connector-c-6.1.11-src/libmysql \
-lmysql \
-o bin/test
ld: library not found for -lmysql
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It's worth noting I am using c not c++ and I am not using XCode just Vim and gcc as can be seen above.
Alternative attempt
I then decided perhaps i've done something wrong with compiling the source from MySQL This particular link and so I deleted the lib directory within my application and installed them via homebrew:
I tried brew install mysql-connector-c I also received the same errors as above despite changing the -I -L -l accordingly the new paths /usr/local/Cellar/... and exactly the same problems were occurring.
Conclusion
I could not find any .c files in any of the compiled mysql libraries, I did find a libmysql inside the source i compiled and attempted to link that which also failed. I personally feel it's a linking problem I just don't know what or how, if anyone could help me with this I would really appreciate it.
Anyone who may want to see the response of -v please see below:
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 305 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -I lib/mysql-connector-c-6.1.11-macos10.12-x86_64/include -I/usr/local/include -Wall -fdebug-compilation-dir /Users/ash/Projects/samp-db2 -ferror-limit 19 -fmessage-length 173 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/v7/_rm0d0qx2r32ln2f7_dpnrw40000gn/T/main-3d5e25.o -x c src/main.c
clang -cc1 version 9.0.0 (clang-900.0.39.2) default target x86_64-apple-darwin17.3.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
lib/mysql-connector-c-6.1.11-macos10.12-x86_64/include
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.13.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -o bin/cmig /var/folders/v7/_rm0d0qx2r32ln2f7_dpnrw40000gn/T/main-3d5e25.o -L/usr/local/lib -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a
> brew install mysql-connector-c
> clang mysql_connect_test.c -l mysqlclient -o mysql_test
> ./mysql_test
MySQL client version: 6.1.11
same code in mysql_connect_test.c, everything is ok.
> ls /usr/local/Cellar/mysql-connector-c/6.1.11/lib
libmysqlclient.18.dylib libmysqlclient.a libmysqlclient.dylib
Your code just need link to libmysqlclient.
And in your post:
gcc src/main.c \
-Wall \
-Ilib/mysql-connector-c-6.1.11-macos10.12-x86_64/include \
-o bin/test
It is wrong, because you just pass library search path to gcc, but also need pass which library you should link, for example, -lmysqlclient.
gcc src/main.c \
-Wall \
-Ilib/mysql-connector-c-6.1.11-macos10.12-x86_64/include \
-Llib/mysql-connector-c-6.1.11-macos10.12-x86_64/mysql-connector-c-6.1.11-src/libmysql \
-lmysql \
-o bin/test
wrong name of link library, and mysql-connector-c-6.1.11-macos10.12-x86_64 just contains source code? If yes, you need compile mysql-connector-c first.
my two cents for Catalina:
Use of external C++ headers in Objective-C
it works, using mysql lib version 21.
NO NEED to use brew or similar..
note:
As that lib is not signed. Simply in Entitlemens:
(in XML): ..
<dict>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
...

GSL library in R

I am writing a C code that I will use in R. To do matrix operations in C, I added "gsl_matrix" library. When I compile using R CMD SHLIB it compiles without problem. However when I open R and try to write dyn.load("file.so"), I receive an error message:
unable to load shared object file.so
undefined symbol: gsl_matrix_alloc
Where is my mistake?
I suspect this has to do with your shared library that is not properly linked to GSL libs, as discussed on R-devel, or the manual on Writing R Extensions, where it is suggested to use a Makevars file (with something like PKG_LIBS=-L/usr/lib -lgsl). Otherwise, following the example in help(SHLIB), you may want to try:
$ R CMD SHLIB file.c -lgsl -lgslcblas
There is a simple tutorial, R Call GSL, which shows basic setup for calling GSL functions.
I am able to reproduce the toy example, that I renamed nperms.{c,r} as follows (on a Mac, whence the use of a -dynamiclib switch in place of -shared):
~/scratch $ gcc -c nperms.c
~/scratch $ file nperms.o
nperms.o: Mach-O 64-bit object x86_64
~/scratch $ gcc -dynamiclib -lgsl -lgslcblas -o libnperms.dylib -dylib nperms.o
~/scratch $ ls *nperm*
libnperms.dylib nperms.c nperms.o
~/scratch $ file libnperms.dylib
libnperms.dylib: Mach-O 64-bit dynamically linked shared library x86_64
Everything works fine when dyn.load'ing libnperms.dylib in R. However, using shared library generated from R CMD SHLIB without further argument
~/scratch $ R CMD SHLIB nperms.c
gcc -arch x86_64 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o nperms.so nperms.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
~/scratch $ ls *nperm*
libnperms.dylib nperms.c nperms.o nperms.r nperms.so
~/scratch $ file nperms.so
nperms.so: Mach-O 64-bit dynamically linked shared library x86_64
raises the following error (sorry for the French locale)
> dyn.load("nperms.so")
Erreur dans dyn.load("nperms.so") :
impossible de charger l'objet partag'e '/Users/chl/scratch/nperms.so':
dlopen(/Users/chl/scratch/nperms.so, 6): Symbol not found: _gsl_permutation_alloc
Referenced from: /Users/chl/scratch/nperms.so
Expected in: flat namespace
in /Users/chl/scratch/nperms.so
I have not a direct answer to your question but did you try http://cran.r-project.org/web/packages/RcppGSL/index.html or http://cran.r-project.org/web/packages/RcppArmadillo/index.html?

How to compile a APR test script

Its a long time since I've used C but now I'm trying to compile a short script that gets server-stats from the Apache-Portable-Runtime (APR).
Header files located at /usr/include/apr-1/apr*.h and libs are located at /usr/lib64/libapr-1.*
Source files can be found on the official APR site http://apr.apache.org/docs/apr/1.3/files.html.
/* test.c */
#include <stdio.h>
#include <stdlib.h>
#include <apr_general.h>
#include <apr_time.h>
int main(int argc, const char *argv[])
{
apr_time_t t;
t = apr_time_now();
printf("The current time: %" APR_TIME_T_FMT "[us]\n", t);
return 0;
}
When I try and compile I get the following error (which I believe is a linking issue):
~> gcc -Wall $(apr-1-config --cflags --cppflags --includes --link-ld) test.c -o test.bin
/tmp/cc4DYD2W.o: In function `main':
test.c:(.text+0x10): undefined reference to `apr_time_now'
collect2: ld returned 1 exit status
My environment is gentoo:
~> uname -a
Linux alister 2.6.32.21-grsec-gt-r2 #1 SMP Tue Sep 7 23:54:49 PDT 2010\
x86_64 Intel(R) Xeon(R) CPU L5640 # 2.27GHz GenuineIntel GNU/Linux`
~> gcc -v
gcc version 4.3.4 (Gentoo 4.3.4 p1.1, pie-10.1.5)
~> emerge --search "%#^dev-lib.*apr"
* dev-libs/apr
Latest version installed: 1.3.9
* dev-libs/apr-util
Latest version installed: 1.3.9
Does anyone with more experience with C on Linux have any suggestions for me to get this working?
As always thanks in advance.
gcc -Wall -I/usr/include/apr-1 -L/usr/lib64 -lapr-1 test.c -o test.bin
-l specifies which shared library to link to, while -L specifies where to look for shared libraries.
APR provides a tool to make this easier, apr-1-config. Something like this should work:
gcc -Wall $(apr-1-config --cflags --cppflags --includes --link-ld) test.c -o test.bin
I finally got around to looking into this.
gcc mentions -l twice in different contexts:
Linker Options
object-file-name -llibrary ...
Directory Options
... -Idir -Ldir ...
so I moved the -llib after the object name (to get the 2nd context) and it compiled!
APR_CFG=$(apr-1-config --cflags --cppflags --includes --link-ld)
gcc -Wall test.c -o test.bin $APR_CFG
./test.bin
The current time: 1332999950442660[us]
I'm not fully sure I understand the linking order and why it didn't work before (if someone could shed some light on that it would be fantastic) but for now I have enough to continue.

Resources