I have pulled down a fresh copy of mbed-os by using the mbed-cli tool.
$ mbed new mbed-os-test
[mbed] Creating new program "mbed-os-test" (git)
[mbed] Adding library "mbed-os" from "https://github.com/ARMmbed/mbed-os" at latest revision in the current branch
[mbed] Updating reference "mbed-os" -> "https://github.com/ARMmbed/mbed-os/#dda7f7d77abd4330b05e686ce3bbe58230eb7876"
Ultimately I am working to enable uVisor on my NXP FRDM-K64F device, but for now I am only using the QuickStart tutorial to get a simple example working without enabling the uVisor.
So, as suggested in the link above, I make a source directory in the newly created clone of mbed-os:
$ mkdir mbed-os-test/mbed-os/source
I copy in the basic main.cpp and compile. It works. However, when I try and create a problem using some of the library routines -- specifically EthernetInterface.
Replacing my simple main.cpp from the uVisor example with the more complicated one (using EthernetInterface) from the above link:
#include "mbed.h"
#include "EthernetInterface.h"
int main() {
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("IP Address is %s\n", eth.getIPAddress());
TCPSocketConnection sock;
sock.connect("mbed.org", 80);
char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
sock.send_all(http_cmd, sizeof(http_cmd)-1);
char buffer[300];
int ret;
while (true) {
ret = sock.receive(buffer, sizeof(buffer)-1);
if (ret <= 0)
break;
buffer[ret] = '\0';
printf("Received %d chars from server:\n%s\n", ret, buffer);
}
sock.close();
eth.disconnect();
while(1) {}
}
Compiling with:
mbed compile -m K64F -t GCC_ARM
I am met with compilation errors stating that the EthernetInterface class does not have members that I am trying to invoke.
../../mbed-os/source/main.cpp: In function 'int main()':
../../mbed-os/source/main.cpp:34:9: error: 'class EthernetInterface' has no member named 'init'
eth.init(); //Use DHCP
^
../../mbed-os/source/main.cpp:36:38: error: 'class EthernetInterface' has no member named 'getIPAddress'
printf("IP Address is %s\n", eth.getIPAddress());
^
../../mbed-os/source/main.cpp:38:5: error: 'TCPSocketConnection' was not declared in this scope
TCPSocketConnection sock;
^
../../mbed-os/source/main.cpp:39:5: error: 'sock' was not declared in this scope
sock.connect("mbed.org", 80);
^
When, of course, the EthernetInterface class does have such members. I think the problem is related to the mbed utilities not compiling against the correct source code because it seems to find the header. If I add a --source= option to the mbed compilation I am met with other errors regarding things that EthernetInterface.cpp includes.
mbed compile -m K64F -t GCC_ARM --source=../libraries/net/eth/EthernetInterface/
[ERROR] In file included from ../libraries/net/eth/EthernetInterface/EthernetInterface.cpp:19:0:
../libraries/net/eth/EthernetInterface/EthernetInterface.h:27:18: fatal error: rtos.h: No such file or directory
The files are certainly contained with mbed-os, I am just not sure how to actually use them.
$ find . -name EthernetInterface.cpp
./libraries/net/eth/EthernetInterface/EthernetInterface.cpp
./features/net/FEATURE_IPV4/lwip-interface/EthernetInterface.cpp
tl;dr -- How can we link against the library code given at libraries/? I can directly include the header files by directly including the file, but the corresponding source appears to be that located in the features/ directory rather than the one in libraries/.
I'm wondering what you're doing that I'm missing, because this works for me:
$ mbed new ethernet-test
$ cd ethernet-test
$ mbed target K64F
$ mbed toolchain GCC_ARM
Open ethernet-test/main.cpp and put in:
#include "mbed.h"
#include "EthernetInterface.h"
int main(int, char**) {
EthernetInterface eth;
eth.connect();
}
Then:
$ mbed compile
...
Total Flash memory (text + data + misc): 108092 bytes
Image: ./.build/K64F/GCC_ARM/ethernet-test.bin
Related
I'm trying to determine the mime-type for several types of files using libmagic and the following bit of code:
auto handle = ::magic_open(MAGIC_MIME_TYPE);
::magic_load(handle, NULL);
// Both of these fail with the same error
// file_path being a const char* with the path to the file.
auto type2 = ::magic_file(handle, file_path);
// svg_content being an std::vector<char> with the contents of the file.
//auto type2 = ::magic_buffer(handle, svg_content.data(), svg_content.size());
if(!type2)
{
std::cout << magic_error(handle) << std::endl;
}
::magic_close(handle);
But for any file or buffer I try I receive regex error, either being or similar to:
46: regex error 17 for `(dryad-bibo/v)[0-9].[0-9]', (match failed)
For example with this .svg file:
<svg xmlns="http://www.w3.org/2000/svg" id="flag-icon-css-no" viewBox="0 0 640 480">
<path fill="#ed2939" d="M0 0h640v480H0z"/>
<path fill="#fff" d="M180 0h120v480H180z"/>
<path fill="#fff" d="M0 180h640v120H0z"/>
<path fill="#002664" d="M210 0h60v480h-60z"/>
<path fill="#002664" d="M0 210h640v60H0z"/>
</svg>
What I've tried so far:
libmagic 5.35
libmagic 5.39
libmagic 5.40
libmagic from opensource.apple
setting LC_TYPE and LANG to "C"
I'm linking against a version of libmagic that was built locally, could there be anything I have missed while building? Are any of the calls incorrect or is there something I'm missing?
I get similar errors when trying to run the related file binary that was compiled locally. Whereas when I use the file command that is available by default I do get image/svg+xml as output.
Edit
To build libmagic (for macOS and Ubuntu), I followed these steps:
Downloaded relevant release from Github
autoreconf --install
./configure
make
make install
Update
It looks like the regex at the bottom of this file is causing issues (at least for the svg):
https://github.com/file/file/blob/b56b58d499dbe58f2bed28e6b3c297fe7add992e/magic/Magdir/dataone
Update 2
Something strange going on; On the system where I've got it working, magic_version() reports 540, as expected. But on the systems where it fails with this error, magic_version() reports 538.
This makes little sense to me as I can't find that version on the system itself anywhere and when I run ./file --version in the build library, it reports file-5.40.
Very dissatisfying answer, but it was linking against GoogleTest causing this error somehow, not even running any tests, just linking against it.
I switched to using Catch2 instead and the issue was resolved.
Tested on Ubuntu 20.04.:
Clone the repo
git clone git#github.com:file/file.git
cd file/
Try this in fresh clone of the repo:
autoreconf -f -i
./configure --disable-silent-rules
make -j4
make -C tests check
And see whether there are any errors reported. After installation with make install, grab some valid xml file named as "test.xml" and put it to some folder together with this main.c:
#include <stdio.h>
#include <magic.h>
int main(void)
{
char *actual_file = "test.xml";
const char *magic_full;
magic_t magic_cookie;
/* MAGIC_MIME tells magic to return a mime of the file,
but you can specify different things */
magic_cookie = magic_open(MAGIC_MIME);
if (magic_cookie == NULL) {
printf("unable to initialize magic library\n");
return 1;
}
printf("Loading default magic database\n");
if (magic_load(magic_cookie, NULL) != 0) {
printf("cannot load magic database - %s\n", magic_error(magic_cookie));
magic_close(magic_cookie);
return 1;
}
magic_full = magic_file(magic_cookie, actual_file);
printf("%s\n", magic_full);
magic_close(magic_cookie);
return 0;
}
(Courtesy to vivithemage.)
Compile and try:
$ gcc main.c -lmagic
$ ./a.out
Loading default magic database
text/xml; charset=us-ascii
If it does not work on your system, report bug on project's bugtracker with specification of your OS and architecture. You can try to hotfix your problem by removing offending record from the file you have found in your update.
I'm trying out OpenTracing Jaeger and have the following file test.cpp:
#include <opentracing/tracer.h>
#include <jaegertracing/Tracer.h>
#include <yaml-cpp/yaml.h>
#include <iostream>
void setUpTracer(const char* configFilePath)
{
auto configYAML = YAML::LoadFile(configFilePath);
auto config = jaegertracing::Config::parse(configYAML);
auto tracer = jaegertracing::Tracer::make(
"example-service", config, jaegertracing::logging::consoleLogger());
opentracing::Tracer::InitGlobal(
std::static_pointer_cast<opentracing::Tracer>(tracer));
}
int main(int argc, char* argv[]){
setUpTracer(argv[1]);
std::cout<<"Hello\n";
return 0;
}
And consider config.yml to be:
disabled: false
reporter:
logSpans: true
sampler:
type: const
param: 1
Now if I compile test.cpp with g++ test.cpp -lopentracing -ljaegertracing -lyaml-cpp and run ./a.out config.yml, I get a
ERROR: cannot connect to socket: Cannot connect socket to remote address { scheme="http", host="127.0.0.1", port=5778, path="/sampling", query="" }
While if I compile with g++ test.cpp -L /usr/local/lib -lopentracing -ljaegertracing -lyaml-cpp, I get a good
INFO: Initializing logging reporter
Hello
The contents of my /usr/local/lib are:
cmake libopentracing.so.1.6.0 libthriftqt.so
libjaegertracing.a libthrift-0.11.0.so libthrift.so
libjaegertracing.so libthrift.a libthriftz-0.11.0.so
libjaegertracing.so.0 libthrift_c_glib.a libthriftz.a
libjaegertracing.so.0.6.0 libthrift_c_glib.la libthriftz.la
libopentracing.a libthrift_c_glib.so libthriftz.so
libopentracing_mocktracer.a libthrift_c_glib.so.0 libyaml-cpp.a
libopentracing_mocktracer.so libthrift_c_glib.so.0.0.0 pkgconfig
libopentracing_mocktracer.so.1 libthrift.la python2.7
libopentracing_mocktracer.so.1.6.0 libthriftqt-0.11.0.so python3.6
libopentracing.so libthriftqt.a
libopentracing.so.1 libthriftqt.la
I'm using Jaeger in conjunction with a larger project involving ROS and get the same error even if I add_compile_options(-L /usr/local/lib) for CMakeLists.txt of the appropriate package; so, I wanted to better understand what the exact cause of the above error is, so hopefully that helps me to fix the one involved in ROS.
Thanks!
You are missing the configuration of Jaeger address. Since you did not provided it, it is trying to connect to the default one, which is TCP protocol, 127.0.0.1 and port 5778.
Check for details the configuration section here.
please any one save my time .my application is written in c++ I was try to startup on boot in ubuntu linux,but when the program try to start it log error like:-
error while loading shared libraries: libocci.so.11.1: cannot open shared object file: No such file or directory
my program use oracle api:-
my start service script which is written in /etc/init.d/sistartup:-
#!/bin/sh
# chkconfig: 345 99 10
OWNER=aki
case "$1" in
'start')
su $OWNER -c "/home/aki/sis_script/startsis.sh >> /home/aki/sis_script/sistartup.log 2>&1" &
# touch /var/lock/subsys/sis_engine
;;
esac
startup script which is written on appropriate user is:-
/home/aki/script/startsis.sh
#!/bin/bash
export TMP=/tmp
export TMPDIR=$TMP
export PATH=/usr/sbin:/usr/local/bin:$PATH
# Start db_test
./home/aki/summ/db_test
My c++ sample test_db.cpp application write below:-
#include <iostream>
#include <occi.h>
#include <string>
using namespace oracle::occi;
using namespace std;
Environment *env;
Connection *con;
int main(){
string user;
string passwd;
string db;
user ="sis";
passwd = "sis10";
db = "localhost:1521/sisdba";
env = Environment::createEnvironment((Environment::Mode)(Environment::OBJECT|Environment::THREADED_MUTEXED));
con = env->createConnection(user, passwd, db);
while(1){
cout<<"Here i have some business which is related to oracle database "<<endl;
}
return 0;
}
After compiling the file in this way
g++ -o db_test test_db.cpp -I$ORACLE_HOME/rdbms/public -L$ORACLE_HOME/lib -locci -lclntsh
I see this error :-
error while loading shared libraries: libocci.so.11.1: cannot open shared object file: No such file or directory
If you have to provide -L$ORACLE_HOME/lib on the build command line, that suggests to me that the libraries aren't in any of the system's library paths, so they won't be found automatically at runtime.
You can confirm this theory by setting LD_LIBRARY_PATH=$ORACLE_HOME/lib before running your program; it should then work. However, depending on your requirements, this may be only worth a temporary workaround (and I'm assuming the $ORACLE_HOME is available!). A more long-term fix might be to add this path to /etc/ld.so.conf, though this then will affect all executables on your system.
Ultimately, you should follow the installation instructions for the library.
did libocci.so.11.1 successfully installed?
I'm trying to compile an run a very basic program given below (test.cpp) which calls the OpenNI class. You can see the files and dirs they're in here. Sorry that some characters screws up a little bit in the browser's encoding. I'm using the linux command: tree, if you know a better command tell me and I will update it.
File Structure
I'm following the guide here, see "GCC / GNU Make".
#include < stdio.h >
#include < OpenNI.h >
using namespace openni;
int
main ( void )
{
Status rc = OpenNI::initialize();
if (rc != STATUS_OK)
{
printf("\nInitialize failed\n%s\n", OpenNI::getExtendedError());
return 1;
}
printf("Hello, world!\n");
return 0;
}
Here is what I'm running in the command line to compile it (gcc 4.7.2):
gcc test.cpp -I../OpenNI-2.0.0/Include -L/home/evan/Code/OpenNi/Init -l OpenNI2 -o test
This works fine but when I run ./test I get the following error:
Initialize failed
DeviceDriver: library handle is invalid for file libOniFile.so
Couldn't understand file 'libOniFile.so' as a device driver
DeviceDriver: library handle is invalid for file libPS1080.so
Couldn't understand file 'libPS1080.so' as a device driver
Found no valid drivers in './OpenNI2/Drivers'
Thanks, any help would be much appreciated.
Instructions from your guide says, that
It is highly suggested to also add the "-Wl,-rpath ./" to your linkage command. Otherwise, the runtime linker will not find the libOpenNI.so file when you run your application. (default Linux behavior is to look for shared objects only in /lib and /usr/lib).
It seems you have exactly this problem -- it can not find some libraries. Try to add proper rpath (seems to be /home/evan/Code/OpenNi/Init/OpenNI2/Drivers in your case) to your compilation string.
I had the same issue after compiling this little "Hello World" with Eclipse and trying to run it in the command line.
The "Wl,-rpath=./" thing did not work for me.
As also discussed here it worked for me after setting some env. variables before execution:
export LD_LIBRARY_PATH="/path/to/OpenNI2:$LD_LIBRARY_PATH"
export OPENNI2_DRIVERS_PATH="/path/to/OpenNI2/Drivers"
export LD_LIBRARY_PATH="/path/to/OpenNI2/Drivers:$LD_LIBRARY_PATH"
Somewhere I got the info that the first two lines should be enough but it was the third line which is important. I does also work just with the third line.
Below is my c++ code and my config file.
when I run spawn-fcgi -a120.0.0.1 -p9000 -n ./rtb.o
I get this error
spawn-fcgi: exec failed: Exec format error
Here is my c++ code that I complied as rtb.o
#include "fcgi_stdio.h"
#include <stdlib.h>
using namespace std;
int main()
{
int count = 1;
while(FCGI_Accept() >= 0)
printf("Content-type: text/html\r\n"
"\r\n"
"<title>FastCGI Hello!</title>"
"<h1>FastCGI Hello!</h1>"
"Request number %d running on host \n",
++count);
return 0;
}
So, what did I do wrong?
You're attempting to run a program called rtb.o? Is this an object file or an executable? You might want to show us how you compile your program. If you're doing something like
g++ -c rtb.cpp
Then you will get an object file and you need to link it to get a working program. Try to run it from your terminal using ./rtb.o. If it prints the same message, then you've got an object file and need to try something like this instead:
g++ -o rtb rtb.cpp
Remember to add a reference to the FCGI library when you link (use the -l option).