GNU gcc/ld – wrapping a call to symbol with caller and callee defined in the same object file

You have to weaken and globalize the symbol using objcopy. -W symbolname –weaken-symbol=symbolname Make symbol symbolname weak. This option may be given more than once. –globalize-symbol=symbolname Give symbol symbolname global scoping so that it is visible outside of the file in which it is defined. This option may be given more than once. This worked … Read more

Very strange linker behavior

The explanation to what’s happening is very simple: Your libgplot.a depends on libm.so, yet the order of -lm and -lgplot on the link line is wrong. The order of libraries on the link line does matter. In general, system libraries (-lpthread, -lm, -lrt, -ldl) should follow everything else on the link line. When you remove … Read more

How to link C++ object files with ld

If you run g++ with the -v flag, you’ll see the link line it uses. Here’s a simple example program: #include <iostream> int main(void) { std::cout << “Hello, world!” << std::endl; return 0; } And the output from running g++ -v -o example example.cpp: Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v –with-pkgversion=’Ubuntu/Linaro 4.4.4-14ubuntu5.1′ … Read more

Why do I have to define LD_LIBRARY_PATH with an export every time I run my application?

You should avoid setting LD_LIBRARY_PATH in your .bashrc. See “Why LD_LIBRARY_PATH is bad” for more information. Use the linker option -rpath while linking so that the dynamic linker knows where to find libsync.so during runtime. gcc … -Wl,-rpath /path/to/library -L/path/to/library -lsync -o sync_test EDIT: Another way would be to use a wrapper like this #!/bin/bash … Read more

What’s the difference between `-rpath-link` and `-L`?

Here is a demo, for GNU ld, of the difference between -L and -rpath-link – and for good measure, the difference between -rpath-link and -rpath. foo.c #include <stdio.h> void foo(void) { puts(__func__); } bar.c #include <stdio.h> void bar(void) { puts(__func__); } foobar.c extern void foo(void); extern void bar(void); void foobar(void) { foo(); bar(); } main.c … Read more

Linking against older symbol version in a .so file

I found the following working solution. First create file memcpy.c: #include <string.h> /* some systems do not have newest memcpy@@GLIBC_2.14 – stay with old good one */ asm (“.symver memcpy, memcpy@GLIBC_2.2.5”); void *__wrap_memcpy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); } No additional CFLAGS needed to compile this file. Then link … Read more

install_name_tool to update a executable to search for dylib in Mac OS X

From otool -l, I analyzed what should be added or modified from the original library and binary. Dylib The change is in id: Load command 2 <– OLD cmd LC_ID_DYLIB cmdsize 40 name libtest.dylib (offset 24) time stamp 1 Wed Dec 31 18:00:01 1969 Load command 2 <– NEW cmd LC_ID_DYLIB cmdsize 64 name @loader_path/../lib/libtest.dylib … Read more

The proper way of forcing a 32-bit compile using CMake

If you want to compile and link for 32 bit using cmake use this for creating libraries and binaries: Creating libraries: add_library(mylib SHARED my_source.c) set_target_properties(mylib PROPERTIES COMPILE_FLAGS “-m32” LINK_FLAGS “-m32”) creating executables: add_executable(mybin sources.c) set_target_properties(mybin PROPERTIES COMPILE_FLAGS “-m32” LINK_FLAGS “-m32”)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)