|
I am using Eclipse IDE and learned long time ago to "add" just name ( bluetooth) in "-l" option.
Eclipse is crazy - the file name is actually bluetooth.a , but the linker is optioned as "-lbluetooth". I could post the linker verbose output , but it is little too long.
My present problem is locating the "library" directory.
I did not install it properly and I am basically starting over.
|
|
|
|
|
Looking at the ld man page, I think you need a different form of the -l option. Try -l:bluetooth.a - note the colon and the .a suffix. When you just use -lbluetooth then the linker will search for a file called libbluetooth.a. I am not sure how you set these options in eclipse (a long time since I used it) but there is probably somewhere in the project settings.
As to the library directory, it should not be too difficult with a find command.
|
|
|
|
|
Looks like you learn something new every day (unless you're careful ). I did not know about the -l:<filename> option for ld. In the past, when I needed to link to static (.a) libs I'd use gcc flags -Wl,-Bstatic -l<lib> -l<lib> ... -Wl,-Bdynamic . The -l:<lib> is nicer, I think. Note that if you omit the trailing -Wl,-Bdyanmic in my solution, then any static system libs (e.g. libc, libstdc++, etc) get linked statically, too, which may not be what you want.
I just tried this and can confirm it works, but you need to use the full filename i.e. -l:libxxxx.a e.g.
$ ls /usr/lib64/lib*.a
/usr/lib64/libc_nonshared.a /usr/lib64/libldc-jit-rt.a /usr/lib64/libmvec_nonshared.a
/usr/lib64/libg.a /usr/lib64/libmcheck.a /usr/lib64/libpthread_nonshared.a
$ g++ hello.cpp -l:mcheck.a -o hello
/usr/bin/ld: cannot find -l:mcheck.a
collect2: error: ld returned 1 exit status
$ g++ hello.cpp -l:libmcheck.a -o hello
$ . That means if your lib actually is $PATH_TO_LIBS/bluetooth.a then -l:bluetooth.a is correct.
|
|
|
|
|
$ g++ hello.cpp -l:mcheck.a -o hello
/usr/bin/ld: cannot find -l:mcheck.a
collect2: error: ld returned 1 exit status
$ g++ hello.cpp -l:libmcheck.a -o hello
Now why are you using the -l: version for a normally named library? For files named libxxx.a all you need is -lxxx , as I explained in my previous post (and in the man page). The only time you need the colon version is if the name does not begin with the lib prefix.
|
|
|
|
|
Richard MacCutchan wrote: The only time you need the colon version is if the name does not begin with the lib prefix.
Or if you want to link to the static version of a library, but not use -static for the whole executable.
It was not clear to me from your post that -l:xxxx.a was looking for a file $SOMEPATH/xxxx.a, since normally a library shared or otherwise would be libxxxx.a. I'm reasonably sure the bluetooth lib the OP is looking for would be libbluetooth.a, since it is part of the bluez package.
|
|
|
|
|
k5054 wrote: It was not clear to me from your post Which is why I specifically mentioned the ld man page, where it is explained.
k5054 wrote: I'm reasonably sure the bluetooth lib the OP is looking for would be libbluetooth.a, since it is part of the bluez package. According to Re: Linking to library - Linux Programming Discussion Boards[^] OP specifies the file does not have the lib prefix.
|
|
|
|
|
OK, I am doing something stupid trying to get # of CPU's in Raspberry Pi.
This returns "syntax error : end of file unexpected " and # of CPU's 512
#include <omp.h>
int iCPU = system ("omp_get_num_procs()");
cout << "# of CPU's " << dec << +iCPU << endl;
exit(1);
Any second opinions ( leading to solution ) are welcome and appreciated.
Cheers
Vaclav
SOLVED
Was missing link to gomp library
modified 8-Feb-19 15:54pm.
|
|
|
|
|
See the man page for system() - its essentially a wrapper around execl() and vfork(). Unless you can execute "omp_get_num_procs()" from the command line, what you have won't work.
Why would you think you need a call to system() in this case?
|
|
|
|
|
This is response from CL on my PC
jim@jim-desktop $ omp_get_num_procs()
>
and this is coming from RPi
pi@pi $ jim@jim-desktop $ omp_get_num_procs()
-bash: syntax error near unexpected token `('
pi@pi $ >
-bash: syntax error near unexpected token `newline'
pi@pi $ sudo omp_get_num_procs()
The purpose / reason was posted in OP.
-bash: syntax error near unexpected token `('
pi@pi $ sudo omp_get_num_procs
sudo: omp_get_num_procs: command not found
pi@pi $
I'll check the man.
|
|
|
|
|
Let me try this another way.
In your last question to this discussion board (from "ls" to C++ buffer?) you asked about capturing the output from system() into your C++ program. I take it from that, that you know what the system() call does - i.e. calls a system command like ls, or ps or grep, etc. So now you seem to be wanting to call a function provided in the omp.h header via the system() call. That makes no sense to me. The only reason I could think you might want to do that was if you were trying to execute the function as a different user - in which case that is not the way to go about that. So my question stands - why are you trying to wrap what appears to be a normal, ordinary C function call inside a call to system()?
|
|
|
|
|
You do not need parentheses on command/program calls in the system. Change your code to:
int iCPU = system ("omp_get_num_procs");
Although I do not expect that a call to system will return the output from the command. Also I suspect you also need to wrap that code in a int main(){} block in order to compile it correctly.
|
|
|
|
|
int main() {
#ifdef STEP
cout << "Project VNAR-19270 VNA-1023 (6 base) Vector network analyzer" << endl;
cout << "DEBUG ****RUNNING WORKING COPY of VNA_2 " << endl;
#endif
int iCPU = 0;
iCPU = system ("omp_get_num_procs");
cout << "# of CPU's " << dec << +iCPU << endl;
exit(1);
Now returns omp_get_num_procs not found.
I think the problem is also in crosscompiler settings.
Also the "remote AKA RPi" OS has no OpenMP installed.
I need to check that.
I was just looking for an advise if my syntax is OK.
|
|
|
|
|
The syntax looks OK now. The error message implies the the omp_get_num_procs program cannot be found in any of the standard locations, so you may need to provide the full path. As I said before, you will not get the correct answer from the call to system ; see the man page for details. In order to get the correct number you need to connect the external command's stdout stream to your application, which you can then read and process as required.
[edit]
You need to re-read k5054's message above.
[/edit]
modified 8-Feb-19 11:54am.
|
|
|
|
|
Richard MacCutchan wrote: The error message implies the the omp_get_num_procs program cannot be found in any of the standard locations
That's not surprising omp_get_num_procs() is a function call in the OpenMP library. I'm not sure why the OP thinks that it needs to be wrapped in a call to system(). If they could answer that question, maybe we can tell him why he's mistaken, and how to fix his mistake.
|
|
|
|
|
Thanks, I see from your previous message that you have explained that.
|
|
|
|
|
int iCPU = 0;
iCPU = omp_get_num_procs();
cout << "# of CPU's " << dec << +iCPU << endl;
exit(1);
Using system( ) because without it I get
./src/VNA_1022_BASE.o: In function `main':
/media/jim/DEV/Eclipse_2019_03_M1/workspace/eclipse-workspace/VNAR_19280/Debug/../src/VNA_1022_BASE.cpp:253: undefined reference to `omp_get_num_procs'
makefile:80: recipe for target 'VNAR_19280' failed
collect2: error: ld returned 1 exit status
make: *** [VNAR_19280] Error 1
"make all" terminated with exit code 2. Build might be incomplete.
I believe it is NOT only syntax issue, but something is missing in setting OpenMP.
I'll take a look at the verbose output of both complier and linker to see anything obvious.
|
|
|
|
|
The linker message undefined reference to `omp_get_num_procs' is the clue, here. You need to tell your IDE to link in libgomp when compiling this project.
What made you think that using system() was the right thing here?
|
|
|
|
|
Habit, used to equerry other system info.
Yes, the linker has given me a hit to check another instruction how to implement OpenMP.
The first one did not included the "link to gomp".
Not everything posted on internet is true and I should have known better anyway.
Now if I can figure out how to tell my IDE to use OpenMP I'll be a happy camper.
|
|
|
|
|
Yes, by using system you are not calling the omp_get_num_procs function at all. You need to understand the difference between using system to run an external application, and calling a library function directly. In the above case you are missing the library that contains the omp_get_num_procs function. So you just need to add it to the LIB section of your makefile, or in the linker section of your project in the IDE (not sure which one you are using here).
modified 9-Feb-19 4:39am.
|
|
|
|
|
"ls" command sends output to "cout".
How do I get it to C++ code buffer?
This code outputs desired /dev/spi x string to a console, I need it to save it in a buffer for further
processing. How?
system("ls -l -x /dev/spi*");
Cheers
Vaclav
|
|
|
|
|
use popen(). e.g.
#include <cstdio>
FILE *cmd = popen("ls -l -x /dev/spi*", "r");
while(!feof(cmd) && !ferr(cmd)) {
fscanf(cmd, ...);
}
fclose(cmd);
If you've got boost, then maybe boost.process will be a better fit.
If you just need filenames, maybe glob() is all you need
#include <glob>
glob_t spi_files;
glob("/dev/spi*", 0, 0, &spi_files);
for(size_t i = 0; i < spi_files.gl_pathc; ++i) {
char *filename = gl.pathv[i];
...
}
globfree(&spi_files);
If you need further information about the files, then you can call stat() on the file, see man stat(2). Also see man glob(3) for the usage of arguments 2 and 3 (0s in above code).
There's also boost.filesystem, which may help you. If you've got a C++17 compilant compiler (gcc v8), then you also have <filesystem> in the stdlib
|
|
|
|
|
Thanks
I just downloaded boost , like to try it, but it does not included format.
I need to figure out how to "insert" format without having to delete ( I have not (intentionally) deleted anything from my OS, scary !) boost and re-install it from a different source.
|
|
|
|
|
Vaclav_ wrote: I just downloaded boost , like to try it, but it does not included format.
I'm not sure what you mean. Are you trying to figure out how to install boost for your OS?
If you have a reasonably recent linux version, you should be able to get boost via the package management system - e.g. apt, yum, etc. But take a look at what version of boost the system is providing, if you're wanting to use boost.process. That was added in v 1.64 which seems to be from April 2017, so that's a recent addition.
|
|
|
|
|
To moderator
I have received e-mail of message flagged as spam.
There is no spam in it, just normal reply.
Funny - how can I receive e-mail of message "pending approval"?
|
|
|
|
|
That just means that the automatic spam filter saw something in the message that may be suspicious. It then holds the message in the pending queue until a member with the relevant authority can review it, and release or reject.
|
|
|
|