Cygwin compile error: "log10l" not recognized (declared) - c++

I am compiling a linux program on cygwin (teaching a class with students that have windows computers) and have run into a problem with compatibility I think.
The error I get is this:
`$ Make
g++ -fopenmp -c start.cpp errors.cpp
start.cpp: In function ‘int main(int, char**)’:
start.cpp:1184:54: error: ‘log10l’ was not declared in this scope
else po[i]=log10l(p_rj[i]/(1-p_rj[i]));
^
Makefile:7: recipe for target 'start.o' failed
Make: *** [start.o] Error 1`
The log10l is not declared. A little research on cygwin's site about this and I found this page which lists "non implemented system interfaces" and log10l is on there.
Do I need to replace 'log10l' with a compatible function and why would't it be compatible?
App compiles without error on my linux box.
Any Help would be much appreciated.
LP

If that function is just taking the log base 10 of the inner expression, you can just replace it with
else po[i] = std::log10(p_rj[i]/(1-p_rj[i]));
As long as you
#include <cmath>

Cygwin does not currently support long double math functions, of which log10l is one. You can use log10 instead, but it is limited to a double type.

Related

Library not found for -lfl

I was using flex and bison to build a simple calculator project I cloned from Github.
But after I typed make in terminal, I got the following message:
gcc -o calc calc.tab.c lex.yy.c -lfl
calc.y:48:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main() {
^~~~
1 warning generated.
ld: library not found for -lfl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [calc] Error 1
How could I resolve this problem?
let me guess, trying to use flex on OS/X?
Try -ll instead of -lfl
Using Flex on OS/X
So yea, the flex library name on OS/X is just arbitrarily different for some reason. OS/X is not exactly Linux, but it's pretty close. You have some options here.
You can just simply have a separate build system and source files for OS/X. Certainly Apple might like that with their pushing XCode, objective-C and not much interoperability.
You can build vs Linux and then engage with Mac Ports and Homebrew.
You can create your project using autotools. That's not an awesome link, learning this system is rough going, but it's a standard thing for Linux for sure. This will actually work, I find if you have the patience for it, OS/X is close enough that autotools based builds will work on it.
Lately, I've been turned on to Cocoapods, which I believe to be an attempt to join the open source community and XCode. It's kind of half 1 and 3 sorta with an emphasis on modularizing the external source and getting it compiled into a .app (via Xcode).
warning: type specifier missing, defaults to 'int'
mean that you should declare return type for main function. Place int in function difinition.
ld: library not found for -lfl
flag -l mean that compiller must use libfl.a to build programm. As #waTeim said above, for Mac OS you can use libl.a instead, but this lib can be not exist alse. There is another way is to place
%option noyywrap
at the top of flex *.l file. In this case you can compile without additional libs.

How to include Accelerate framework with i686-apple-darwin11-llvm-g++-4.2?

I am trying to use the Accelerate framework on a small C++ program. I'm not even using XCode, only a simple Makefile.
The compiler complains when I add the following line to my code:
#include <Accelerate/Accelerate.h>
The error is the following:
In file included from /System/Library/Frameworks/vecLib.framework/Headers/vecLib.h:41,
from /System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h:20,
from Diana.cpp:20:
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected identifier before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected `}' before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected unqualified-id before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9028: error: expected declaration before ‘}’ token
The compiler I'm using is i686-apple-darwin11-llvm-g++-4.2, which is a gcc 4.2.1, and the line that I use to compile (not to link) is:
i686-apple-darwin11-llvm-g++-4.2 -D__MACOSX_CORE__ -c -o Diana.o Diana.cpp
Should I add some additional flag(s) when compiling this? I tried adding the "-framework Accelerate", but it doesn't change anything, since this should only be included in the linkage process (am I right?).
I googled some of these error messages and I didn't find anything.
I would really appreciate any help. Thank you!
PS: My OS X version is Lion 10.7.5, and XCode is 4.4.1.
I figured it out: I checked what was on line 9008 of vDSP.h and the problem was that I was declaring an FFT_FORWARD constant before including the Accelerate.h.
Fixed!

Visual Studio C++/OpenCL project using Boost not compiling with g++ on Linux

First some background - I have three VS2010 C++/OpenCL projects that compile and run fine on Windows 7 64-bit. I've been trying to compile and run each of them on Linux 64-bit (Ubuntu/Debian). The first two are compiling and running on linux and don't really use any external libraries. The third uses only Boost 1.50.0 and isn't compiling using the same method as the first two. So first let me go through what I did to get the first two to work.
I extracted only the source from the myriad of folders.
I ported windows specific code to linux specific code.
I wrote a bash script to generate the g++ command with all sources to compile them.
I ran the compile script to generate an output target file.
The bash script is as follows.
#!/bin/bash
SOURCE=""
for i in `ls *.h *.cpp *.hpp`; do
SOURCE+="${i} "
done
COMMAND="g++ -I/home/junkie/downloads/boost_1_51_0 -o out ${SOURCE} -L/opt/AMDAPP/lib/x86_64/ -I/opt/AMDAPP/include -lOpenCL -fpermissive"
echo -e "\n"
echo -e "${COMMAND}"
echo -e "\n"
$COMMAND
exit $?
And it generates and runs a command similar to following.
g++ -I/home/junkie/downloads/boost_1_51_0 -o out blah.cpp blah.h foo.hpp baz.cpp etc.cpp -L/opt/AMDAPP/lib/x86_64/ -I/opt/AMDAPP/include -lOpenCL -fpermissive
I compile using the following command.
./compile.sh &> log; echo $?; grep -ci error log; wc -l log
Now you may be wondering why I've adopted such unconventional and redundant means of getting a C++ project to compile and run on linux. Well because I'm new to the linux c and c++ toolchain and this was the quickest and simplest route I could figure out to get the job done and it did get the first two projects up and running. However, the third uses boost and this method isn't working and I need your help in figuring out what all these strange errors are.
The errors I'm getting are not actually from the project code but instead from Boost and AMD's opencl libraries code which is strange because the other projects were using opencl too and those worked fine.
Some examples of boost errors are below.
foo.hpp:2331:1: error: unterminated argument list invoking macro "BOOST_PP_CAT_I"
In file included from main.cpp:4:
foo2.hpp:1610:1: error: unterminated argument list invoking macro "BOOST_PP_CAT_I"
/home/junkie/downloads/boost_1_51_0/boost/preprocessor/cat.hpp:22: error: variable or field ‘BOOST_PP_CAT_I’ declared void /home/junkie/downloads/boost_1_51_0/boost/preprocessor/cat.hpp: At global scope:
/home/junkie/downloads/boost_1_51_0/boost/preprocessor/cat.hpp:22: error: variable or field ‘BOOST_PP_CAT_I’ declared void
/home/junkie/downloads/boost_1_51_0/boost/preprocessor/cat.hpp:22: error: expected ‘;’ at end of input
/home/junkie/downloads/boost_1_51_0/boost/preprocessor/cat.hpp:22: error: expected ‘;’ at end of input
/home/junkie/downloads/boost_1_51_0/boost/preprocessor/cat.hpp:22: error: expected ‘}’ at end of input
/home/junkie/downloads/boost_1_51_0/boost/preprocessor/cat.hpp:22: error: expected unqualified-id at end of input
/home/junkie/downloads/boost_1_51_0/boost/preprocessor/cat.hpp:22: error: expected ‘}’ at end of input
/home/junkie/downloads/boost_1_51_0/boost/preprocessor/cat.hpp:22: error: expected ‘}’ at end of input
foo.hpp:2331:1: error: unterminated argument list invoking macro "BOOST_PP_CAT_I"
Some examples of opencl errors are below.
In file included from /opt/AMDAPP/include/CL/cl_platform.h:35,
from /opt/AMDAPP/include/CL/cl.h:30,
from bar.h:7,
from fooGPU.hpp:6,
from main.cpp:4:
/usr/include/stdint.h:49: error: expected ‘;’ before ‘typedef’
In file included from /opt/AMDAPP/include/CL/cl.h:30,
from bar.h:7,
from fooGPU.hpp:6,
from main.cpp:4:
/opt/AMDAPP/include/CL/cl_platform.h:41: error: expected unqualified-id before string constant
main.cpp:136: error: expected ‘}’ at end of input
main.cpp:136: error: expected unqualified-id at end of input
main.cpp:136: error: expected ‘}’ at end of input
main.cpp:136: error: expected ‘}’ at end of input
The boost includes I'm Using are as follows.
#include <boost/preprocessor/punctuation/paren.hpp>
#include <boost/preprocessor/punctuation/comma.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/logical.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/array.hpp>
So, finally, my questions are as follows.
1) What is the root cause of these errors in light of the building method I'm using and how do I resolve this problem? Does order of files or library inclusion matter? I'm using a local source download of boost as part of my g++ command as instructed by boost documentation rather than prebuilt binaries as I'm not using anything that requires prebuilt binaries.
2) I realise that my way of building things is pretty primitive. I'm learning make and I've seen some recommendations to use cmake and kdevelop which I need to look into. The primary problem with using make is that these projects weren't written with make in mind so I'm not aware of the dependency graph between source files to create the makefile (if I'm thinking correctly; I'm still fairly new to it). If you have any recommendations of how to do things better please do enlighten me.
Thanks.
I finally managed to overcome this problem and here I provide a brief account of how. To be clear I don't know what the root cause of the original problem was. In other words - I don't know why the problem occurred. All I'm saying is that my workaround allowed me to resolve the issue and move onto other problems (compile time errors).
Essentially, to reiterate, the problem was that for whatever reason a project using boost wasn't compiling on Linux because all instances of the use of the BOOST_PP_CAT() function produced the following error.
error: unterminated argument list invoking macro "BOOST_PP_CAT_I"
For whatever reason the compiler wasn't able to correctly process the use of this function but was able to process the use of other boost functions such as BOOST_PP_LPAREN(), BOOST_PP_RPAREN() and BOOST_PP_COMMA. The problem looked almost certainly related to the preprocessing stage where the combined use of the aforementioned boost functions was resulting in an unterminated argument list.
To elaborate on the nature of the relevant code (which was not written by me thankfully) the prior developers had essentially used boost preprocessor functions to create a DSL that they could then re-use multiple times to generate a list of functions. It would have seemed a lot easier to me to simply write the functions directly but anyway that's another concern.
My work around was to change the relevant section of code so that it didn't use any BOOST_PP_CAT() functions but ultimately defined the exact same functions as before. I did this by substituting the use of BOOST_PP_CAT() with the code that was being generated by it. This overcame all instances of the error quoted above but left me with hundreds of other compile time errors in my efforts to migrate this project from windows to linux.
Although this was a very specific and unusual question with an equally specific and unusual answer I wanted to feed this back to dispel the mystery behind this problem. As to why this particular function was failing to preprocess/compile on linux but passing on Windows I don't know but would very much like to know. I can only assume it is a fundamental difference in the way VC++ performs preprocessing as opposed to g++ and clang or more specifically perhaps a difference in the order of resolution of nested functions in preprocessor directives. Who knows. Anyway, thanks for your help guys.
The unterminated argument list invoking macro error suggests a lacking closing parenthesis. Use your editor's parenthesis matcher to check it. Be sure that your source files are in Unix format, not in DOS format (e.g. with \n à la Unix, not with\r\n à la MSDOS, at each end-of-line). Use dos2unix if needed.
Otherwise, don't forget that you can run g++ -Wall -C -E -H -I/home/junkie/downloads/boost_1_51_0 yoursourcecode.cc to get the preprocessed form of yoursourcecode.cc, and, by redirecting that command, you can inspect that preprocessed form with the editor of your choice (like emacs).
As I commented, learn to use Gnu make (and if in trouble debugging your Makefile, which you should edit with a good editor like emacs, use remake -x to debug it).
And the -I/home/junkie/downloads/boost_1_51_0 looks very suspicious: even if Boost is often a header only library, it has, as far as I remember, an installation procedure on Unix (and Linux distributions often package Boost libs). You should install your Boost libraries as documented (and after having configured them), and likewise for OpenCL.

How to compile C++ files generated by google's protobuf compiler on OS X

I'm using a Mac. I have a library written in C++, let's call it "wibble", along with its source code. I can compile this source with GCC 4.3 from macports (g++-mp-4.3), and can link the resulting library into other stuff as long as I use GCC 4.3.
However, I need to link this into another application (let's call it "blort") which will only load libs compiled with the GCC 4.2 that is bundled with OS X 10.6 (because that's what it was built with)
I can, more or less, mess with wibble's Makefile however I may please, but blort is a fixed target. I can write whatever code or build scripts to glue them together I may need. There appears to be no way to get wibble to compile on 4.2 (barring a rewrite, which is out of the question), and the guy who wrote it confirms that.
I am not very familiar with the whole build and linking process in C++, having only been handed this integration, and am completely stumped. Is what I'm trying to achieve even possible? If so, how?
In case it matters, what I'm trying to do is call the methods in wibble from Perl via Inline::CPP, but I'm willing to write raw XS if I have to (I've done that before, at least). I need to use the system perl so this will easily build and install on other people's machines. :-/
UPDATE, 2012-03-01, 1
I am looking into compiling protobufs using the Mac's compiler, and seeing if I can get wibble to compile with the same compiler using that build of protobufs. I will post the results shortly.
Hrmph same errors:
g++ -Wall -Wno-unused-function -Wno-long-long -pedantic -O3 -I/Users/sscaffid/local/include -L/Users/sscaffid/local/lib -fPIC -std=c++98 -c wire.pb.cc
In file included from /Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:43,
from wire.pb.cc:10:
/Users/sscaffid/local/include/google/protobuf/wire_format_lite.h:94: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/wire_format_lite.h:117: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/wire_format_lite.h:132: error: comma at end of enumerator list
In file included from wire.pb.cc:10:
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:303: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:304: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:305: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:306: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:307: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:308: error: extra ‘;’
In file included from wire.pb.cc:11:
/Users/sscaffid/local/include/google/protobuf/descriptor.h:322: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/descriptor.h:341: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/descriptor.h:352: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1206: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1223: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1243: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1249: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1257: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1264: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1274: error: extra ‘;’
In file included from wire.pb.cc:13:
/Users/sscaffid/local/include/google/protobuf/wire_format.h:226: error: comma at end of enumerator list
make: *** [wire.pb.o] Error 1
From the question:
Solution:
Using the -pedantic option to GCC 4.2 makes it very angry with protobuf code. Don't use it.

Embedding Python in C++ libraries

I'm working on embedding Python in some C++ code, but I'm getting stuck compiling it.
For a header file, I have
#include <Python.h>
I would initial try,
$g++ EmbeddedPython.cpp
but would end up getting
EmbeddedPython.cpp:1:20: error: Python.h: No such file or directory
EmbeddedPython.cpp: In function ‘int main(int, char**)’:
EmbeddedPython.cpp:6: error: ‘Py_Initialize’ was not declared in this scope
....
I then tried
g++ EmbeddedPython.cpp -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5
and that got rid of the first two errors, but I still ended up with
Undefined symbols:
"_Py_Initialize", referenced from:
_main in ccxJAUAB.o
I'm a bit of new to this, but I think I'm learning fast. I believe I need to 'Link' a library, right? But which one and how? Do I need a dynamic or a static one?
I am working on a MacBook Pro.
You need to link against libpython. UNIX programmers do this with "-lpython" in the link command (ie at the end of that "g++" command). On a Mac, I think it would be "-framework Python".