rudimeier / twsapi

portable C++ API for Interactive Brokers TWS
128 stars 69 forks source link

Linking to library #11

Closed benharbit closed 6 years ago

benharbit commented 6 years ago

So how do I link to the libtwsapi library

I try the follow for the TestCppClient, but I get undefined reference errors. I can get it to work with the original makefile.

g++ -pthread -Wall -Wno-switch -std=c++11 -I/home/my_location//twsapi-master/cpp/client -I/home/my_location/twsapi-master/cpp -ltwsapi -ltwsapi-iborig ./*.cpp -o TestCppClient

benharbit commented 6 years ago

oh, you have to include the libary after the cpp files. I figured it out.

rudimeier commented 6 years ago

oh, you have to include the libary after the cpp files. I figured it out.

Yes, also note that probably you only need -ltwsapi-iborig. The other -ltwsapi is needed only if you include the re-added single threaded EPosixClientSocket from cpp/suppl/.

BTW I recommend to "make install" the library, which makes it much easier to use. You can install it as a normal user into whatever location, e.g. I use:

./configure --prefix /home/rudi/usr/local/twsapi-next
make install

It will also install "*.pc" files (pkg-config) which contain the right compiler and linker flags.

For example on my system it looks like this

$ pkg-config --cflags  ~/usr/local/twsapi-next/lib64/pkgconfig/twsapi-iborig.pc
-DIBString=std::string -I/home/rudi/usr/local/twsapi-next/include

$ pkg-config --libs  ~/usr/local/twsapi-next/lib64/pkgconfig/twsapi-iborig.pc
-L/home/rudi/usr/local/twsapi-next/lib64 -ltwsapi-iborig -pthread -lssl -lcrypto