2019年5月13日星期一

making a static lib using another static lib

8
Static libraries are just archives of object (.o) files, so you can't have embedded dependency information. Something like ar cr lib1.a foo.o bar.o [more object files] will build your libraries.
Because there is no dependency information, your main program has to link both the libraries and it's important to link lib1 after lib2 when lib2 depends on lib1 (otherwise the linker won't find the symbols that are unresolved in lib2). A linking step could therefore look like this (assuming you use gcc and your libraries are in the current directory):
gcc -otest main.o -L. -Wl,-Bstatic -l2 -l1
  • +1 I thought the same but due to less experience in C I didn't answered. (Y) – Harneet Singh Aug 5 '17 at 12:19
  • @rici the linker is not in the scope of the standard. This is about the GNU linker. You can list the same library twice in an invocation if necessary. – user2371524 Aug 5 '17 at 14:45
  • For libraries, it is possible to place them twice on the command line:-l1 -l2 -l1 will handle references in either direction including mutual recursion. – rici Aug 5 '17 at 14:49
  • That's what I just wrote, responding to your now-deleted comment. – user2371524 Aug 5 '17 at 14:50
  • Felix, libraries are not in scope but the linker is part of the implementation. The standard provides for translation units and a mechanism to run a complete program, so there must be something like a linker. – rici Aug 5 '17 at 14:56
  • As to the other, i misread your answer so i deleted the complaint. Typing on glass is slow, at least for me. Sorry for the confusion. – rici Aug 5 '17 at 14:57 
  • Isn't there a way to make l2.lib contain the l1.lib objects as well? So when linking to the parent project of l2.lib only l2.lib will be linked? – Royi Apr 20 at 6:54

2019年5月5日星期日

show macro debug info

gcc -g3 testxed.c -Ixed/include xed/lib/libxed.a -o testxed

readelf --debug-dump=macro ./testxed

2019年4月10日星期三

c++ get member function's address

There exists a syntax to get the address of the member function in MSVC (starting from MSVC 2005 IMHO). But it's pretty tricky. Moreover, the obtained pointer is impossible to cast to other pointer type by conventional means. Though there exists a way to do this nevertheless.
Here's the example:
// class declaration
class MyClass
{
public:
    void Func();
    void Func(int a, int b);
};

// get the pointer to the member function
void (__thiscall MyClass::* pFunc)(int, int) = &MyClass::Func;

// naive pointer cast
void* pPtr = (void*) pFunc; // oops! this doesn't compile!

// another try
void* pPtr = reinterpret_cast<void*>(pFunc); // Damn! Still doesn't compile (why?!)

// tricky cast
void* pPtr = (void*&) pFunc; // this works
The fact that conventional cast doesn't work, even with reinterpret_cast probably means that MS doesn't recommend this casting very strongly.
Nevertheless you may do this. Of course this is all implementation-dependent, you must know the appropriate calling convention to do the thunking + have appropriate assembler skills.


or



4
try this. should let you cast anything to anything :)
template<typename OUT, typename IN>
OUT ForceCast( IN in )
{
    union
    {
        IN  in;
        OUT out;
    }
    u = { in };

    return u.out;
};
then
void* member_address = ForceCast<void*>(&SomeClass::SomeMethod);

2019年4月9日星期二

qt

The system might have different meta packages that handle the default. For example on Debian there is a qt4-default and a qt5-default package, installing one of them will uninstall the other and set the symlinks appropriately

Remote Window Managers

Remote Window Managers


Lots of times it's extremely frustrating or time consuming to run an xterm on a remote host just to fork your programs from that remote machine. Why not just run your window manager there even though you're not on its console? The window manager is just another X application, after all, isn't it?
Fire off your local X server
xinit /usr/bin/xterm -- :1 &
yields a vanilla X session with merely an xterm running - no window manager. Now you need to add permissions to this window session for the remote host. You can tunnel the connection through SSH if your network is insecure but there's a distinct performance hit. If your network is secure, you can just "xhost +remotehost" and spray directly to your X server:
Tunneled SSH:
ssh -fY remotehost /usr/bin/wmaker
or spray directly:
xhost +remotehost
ssh -f remotehost /usr/bin/wmaker -display localmachine:1
The first option, if your remote SSH server supports it, will use a locally defined DISPLAY that then gets tunneled to your local side over SSH. The second option allows remotehost to send X data directly to your local display, then runs WindowMaker there but displaying it locally. Now all your desktop actions are done on the remote machine, not locally.
Our special thanks to Bill from Washington state for this tech tip.

2019年2月20日星期三

Xterm setting, ture type font

$vi ~/.Xresources

XTerm*renderFont: true
XTerm*faceName: VeraMono
XTerm*faceSize: 10


// Merge in changes to a running X session with:
$ xrdb -merge ~/.Xresources



http://www.futurile.net/2016/06/14/xterm-setup-and-truetype-font-configuration/



copy & paste from xterm

$vi ~/.Xresources
xterm*VT100.Translations: #override \
                 Ctrl Shift <Key>V:    insert-selection(SELECT) \n\
                 Ctrl Shift <Key>C:    copy-selection(SELECT)

$ xrdb -merge ~/.Xresources

2018年11月28日星期三

lxc launch a new container

lxc launch ubuntu:16.04 first

lxc exec first -- /bin/bash

userdel ubuntu

adduser --home /home/u --shell /bin/bash u

usermod u -aG sudo


/etc/init.d/ssh start
or
service ssh start
or
systemctl start ssh


vi /etc/ssh/sshd_config

PasswordAuthentication no --> yes

service ssh restart


lxc config device add xxx projectdir disk source=/home/user/prjs path=/home/user/prjs

lxc stop xxx
lxc config set xxx raw.idmap 'both 1000 1000'
lxc start xxx