FreeOpcUa / freeopcua

Open Source C++ OPC-UA Server and Client Library
http://freeopcua.github.io/
GNU Lesser General Public License v3.0
713 stars 341 forks source link

Installing library ubuntu #300

Open uprightcarrion opened 6 years ago

uprightcarrion commented 6 years ago

I'm having some trouble installing the library. I'm using ubuntu so I ran the .soft script, I built it using autoconf, and ran make install. Everything seems to have gone ok. I copied the example server code but I can't get it to build.

Problem 1: it couldn't find the headers so I manually moved the opc folder from the include folder to /usr/include. The compiler was then able to find the headers.

Problem 2: Now that the headers are found I get build errors complain undefined references related to opcua.

I'm sure I'm doing it wrong. I'm using CodeBlocks and haven't done anything special compiler configurations.

buildErrors.txt

f0urex commented 6 years ago

I'm newbee and I have this problem too

guqinchen commented 6 years ago

@uprightcarrion I don't have problem 1 by calling sudo make install However, I do have problem 2. Did you eventually solve the problem?

uprightcarrion commented 6 years ago

@guqinchen unfortunately no I wan't able to get past this. I chopped it up to my lack of C/C++ experience. I've been using the python wrapper. I'd like to come back to this and try again, if you happen to get it figured out before I do post it here. I'll do the same.

uprightcarrion commented 6 years ago

@guqinchen I tried it again for a few min and still got hung up at the same spot I believe. I can build the library using cmake but I can't build built the example_server.cpp. I get numerous errors such as undefined reference to `OpcUa::NodeId::NodeId(OpcUa::NodeId const&). I'm certain the issue is with the way I'm building it with g++. All I use is "g++ example_server.cpp".

I also ran sudo make install after I built it thinking that it would put all the required files where they belong, no luck.

uprightcarrion commented 6 years ago

@guqinchen Ok..some progress. I was able to build the example_server.cpp with "g++ example_server.cpp -Llib -lopcuacore -lopcuaserver -lopcuaprotocol -lopcuaclient -lpthread" but the when I run the executable I get "./a.out: error while loading shared libraries: libopcuacore.so: cannot open shared object file: No such file or directory".

Some of those includes I'm sure are not required.

Ok so after building to executable to get it to run I had to run "sudo ldconfig" in order for it to find the .so files.

To build on ubuntu 18.04 I needed to install the following libpthread-stubs0-dev libmbedtls-dev libboost-program-options-dev libboost-filesystem-dev libboost-thread-dev libboost-system-dev

@guqinchen I hope this helps you

Also you don't need -lopcuaclient to build the server

And if you run the make install then run sudo ldconfig then you don't need to use the -Llib flag. I added the lib folder from the opcua project to my working directory just trying to get it to work.

And finally to build the example_client.cpp I did g++ example_client.cpp -lopcuacore -lopcuaclient -lopcuaprotocol -lpthread -lmbedtls -lmbedcrypto -lmbedx509 -o client

Seems to be working now

guqinchen commented 6 years ago

@uprightcarrion I really appreciate your help! I can successfully build and run the example_server.cpp now.

For me, I observed the installation process first by following the "Using cmake - Linux" instruction in README, and found that I needed to install boost and mbedtls library. So I installed boost with sudo apt-get install libboost-all-dev, and installed mbedtls with

git clone https://github.com/ARMmbed/mbedtls.git
cd mbedtls
sudo make install

Then freeopcua will install successfully with sudo make install.

I was initially stuck with the linking process during compiling the example server program. I was suspecting that gcc was able to find the header files but could not link to the library files, but was unsure how to solve this. Fortunately, your method worked for me! To narrow it down to the minimal argument set, I called g++ example_server.cpp -lopcuacore -lopcuaprotocol -lopcuaserver -lpthread -o example_server without further calling 'sudo ldconfig'. Now it seems to work just fine!

Also in case you are interested in an alternative (since this repo hasn't been updated for a while, unlike the Python version), I have already managed to use Python embedding to call the Python APIs and integrate with a C++ project. I know this sounds silly, but it was the only thing I could do and it worked.

uprightcarrion commented 6 years ago

@guqinchen no problem, I'm glad I got it to work this time. I guess I've learned a little more since last time I took a whack at it. I'm sure there are probably better methods but I'll learn more as a go.