rl_replace_line of readline library impossible to build on mac os - c

Recently I built a microshell program on Linux. I wanted to work on my MacBookPro (Big Sur 11.6.2) and found out that I'm having issue to compile my program because of the function rl_replace_line of the readline library.
I compile with :
clang -Wall -Wextra -Werror -I./includes
The error I'm having is :
error: implicit declaration of function 'rl_replace_line' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
I found another question on stackoverflow and the answer was to compile with :
-L .brew/opt/readline/lib and -I .brew/opt/readline/include
It doesn't work for me and I'm still having the same error. I tried what brew suggest which is to do :
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"
I also tried to compile with -lreadline and it doesn't work.
It still doesn't work for me.
Any idea what I could try to solve this issue ?
Thank you !

Related

What are the correct flags for linking to gslcblas libraries when they are not in /usr/local/lib?

On my personal laptop I enter
gcc -std=gnu99 -lm -lgsl -lgslcblas equal_runtimes.c particle_filters.c solvers.c -o equal_runtimes
in the terminal to compile my C code and have no issues. As far as I know this is because the gsl headers and libraries are on the standard search paths /usr/local/include and /usr/local/lib respectively (https://www.gnu.org/software/gsl/doc/html/usage.html).
However, when I try to compile the same code with the above commands on a system in which the headers/libraries are located in /apps/gsl/2.1/include and /apps/gsl/2.1/lib respectively, I get the warning
warning: implicit declaration of function ‘gsl_blas_dgemv’ [-Wimplicit-function-declaration]
Therefore it seems the compiler is not linking the gsl libraries, as it's assuming gsl_blas_dgemv is my function. To try to fix this I've followed the guidance at the above gnu.org link, for which the best I can come up with is
gcc -L/apps/gsl/2.1/lib -std=gnu99 -lm -lgsl -lgslcblas equal_runtimes.c particle_filters.c solvers.c -o equal_runtimes
but still no success. Is there an issue with the above syntax I'm using or is there something else here that I'm missing?
Following on from #Eric Potpischil's comments, the problem was the wrong header <gsl/gsl_cblas.h> being used for gsl_blas_dgemv instead of the correct <gsl/gsl_blas.h>. This was not an issue on my own system as the blas library would automatically be found by virtue of its location, which was not the case when using the external system.

Compiling a c program on linux ubuntu

Hey guys please help me out here. I have made a c program. I'm new to it and compiling it and i'm getting an error thats making me pull my hair out.
error
as: unrecognized option "--32"
I've tried using gcc -c, gcc -o to no avail.
however, using gcc -S to get a asm file works.
What am I doing wrong?
EDIT: I've tried
gcc -c verilog.c
gcc -o verilog verilog.c
gcc -o verilog.c
gcc verilog.c -o verilog
I also got a warning on a part of my code but that wouldnt stop the compilation though right?

How do I patch libxml2 so it will compile with ICU support when using a prefix?

I'm trying to fix a bug in libxml2. I cannot get it to compile with --with-icu when using --prefix=/Server/software. I have submitted a bug report here, but I need to get it to compile for resolving a conflict when compiling PHP with intl support. I suspect it's a problem with the Makefile. My experience with Makefile's is limited. The desired result is coming up with a patch that can be submitted to the linked bug report.
The --with-icu flag causes LIBXML_ICU_ENABLED to be defined. The included code is supposed to resolve a conflict when including headers from both icu and libxml2 (specifically, both use UChar). The PHP plugin intl, activated with --enable-intl, requires icu. libxml2 is needed by PHP for DOM/XML functions.
There are two problems.
First, this config:
./configure --prefix=/Server/software --enable-shared --enable-static --with-icu
Results in:
configure: error: libicu config program icu-config not found
This happens because of this code in configure.in:
WITH_ICU=0
if test "$with_icu" != "yes" ; then
echo Disabling ICU support
else
ICU_CONFIG=icu-config
if ${ICU_CONFIG} --cflags >/dev/null 2>&1
then
ICU_LIBS=`icu-config --ldflags`
LDFLAGS="$LDFLAGS $ICU_LIBS"
WITH_ICU=1
echo Enabling ICU support
else
AC_MSG_ERROR([libicu config program icu-config not found])
fi
fi
Specifically ICUCONFIG=icu-config isn't respecting --prefix=/Server/software. I can work around this by doing export PATH=/Server/software/bin:$PATH.
This "fixes" the ./configure problem.
Second, when I run make I get errors, the most relavent being:
./include/libxml/encoding.h:31:26: error: unicode/ucnv.h: No such file or
directory
The unicode/uncv.h file is in /Server/software/include/unicode/uncv.h. I suspect the compiler is looking for this file in the local directory and in my /usr directory.
This is what the error is referring to:
#ifdef LIBXML_ICU_ENABLED
#include <unicode/ucnv.h>
#endif
Clearly this is a path issue when using --with-icu and --prefix=/Server/software. Without --with-icu it compiles fine, but this is needed to resolve a define UChar conflict when compiling PHP with both icu and libxml2.
The result of icu-config --cflags is:
-O2 -Wall -ansi -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -Wno-long-long
This is being piped into /dev/null.
The result of icu-config --ldflags is:
-lpthread -lm -L/Server/software/lib -licui18n -licuuc -licudata -lpthread -lm
What needs to be changed to resolve these issues?
So, take a look at where it's using icu-config. It should be doing something like icu-config --cppflags which should set -I/Server/Software/include or similar. You could work around it by setting CPPFLAGS to include such a parameter yourself.
Can you include the actual compile command line immediately before the error?
Sounds like a bug in libxml - it ought to search ${PREFIX}/bin for icu-config.
Also, ICU now exports pkg-config files, which are more of a standard way to find such items.
Try this before WITH_ICU :
ICU_CPPFLAGS=`icu-config --cppflags`
CPPFLAGS="$CPPFLAGS $ICU_CPPFLAGS"
update I'm going to quote Luke's last response. Glad it's working.
I solved the linker problems, so now it all works. For this question
using libxml 2.7.7 was the solution. It seems OX X 10.6 ships with
2.7.8. So for it to work you have to compile libxml2 yourself with 2.7.7. The linker problems are solved by adding LIBS="-lresolv -lstdc++" just before PHP's ./configure. If installing to a non-standard location you also need to compile ICU with
--enable-rpath. I've accepted your answer. Feel free to update it with this information :). – Luke 17 hours ago

Example code given for curve fitting with Gnu Scientific Library wont run.

I am trying to use GSL for least square fitting, but I can't even make the example run properly. It compiles, but when running the program it gives the error
dyld: lazy symbol binding failed: Symbol not found: _cblas_dnrm2
Referenced from: /usr/local/lib/libgsl.0.dylib
Expected in: dynamic lookup
I believe I have narrowed down the problem to the line
gsl_multifit_fdfsolver_set (s, &f, &x.vector);
but I have not the slightest clue why.
I am running it on OSX with GSL 1.15 (though I innitially insalled the wrong version, 1.9). I compile it in the terminal using: gcc unchanged_example.c -o examplefitter -lgsl -lm
EDIT: solution was found here. adding '-lgslcblas' when compiling sorted it out
For anyone coming across this you need to link against two libraries...
gcc -Wall -O3 -g -lgslcblas -lgsl -std=c11 -pedantic-errors
You need to find the shared library that contains _cblas_dnrm2 and link it into your application.

How to force OpenMPI to use GCC instead of ICC? Is recompiling OpenMPI necessary?

I have a C-code for parallel computing written for gcc, and I want to compile it on a cluster, which apparently uses icc via mpicc. Correcting the code to be icc-friendly seems to be too time-demanding, so I wonder if I can ask OpenMPI to use gcc instead. I don't have the admin rights on that cluster, and I would actually prefer to do not mess the original configuration.
If it is not possible to set in e.g. Makefile, then I could hopefully compile OpenMPI in my home directory, but I need some guidance in what must be done after that. Could you help me?
UPDATE1
The Makefile contains
CC = mpicc
CFLAGS += -DMPI
And here are some OpenMPI files
$ which mpicc
/usr/bin/mpicc
lrwxr-xr-x /usr/bin/mpicc -> opal_wrapper
-rwxr-xr-x /usr/bin/opal_wrapper
Let me know, if I can provide you more information.
UPDATE2
With the help of Jeff, I was able to find OpenMPI settings for mpicc
$ more /usr/local/share/openmpi/mpicc-wrapper-data.txt
project=Open MPI
project_short=OMPI
version=1.1.4
language=C
compiler_env=CC
compiler_flags_env=CFLAGS
compiler=icc
extra_includes= openmpi
preprocessor_flags=
compiler_flags=-pthread
linker_flags=
libs=-lmpi -lorte -lopal -ldl -Wl,--export-dynamic -lnsl -lutil -ldl
required_file=
However, I do not have rights to edit this file, and OPMI_CC = gcc doesn't change compiler.
UPDATE3
Environmental variable CC = gcc doesn't help
$ export CC=gcc
$ echo $CC
gcc
$ make clean $$ make
...icc:...errors
UPDATE4
...but export OMPI_CC=gcc does finally help (thanks to sharth). I should one day remember that these are different things...
Despite that the binary was created, I got the following bye-bye message
/opt/intel/fce/9.1.036/lib/libimf.so: warning: warning: feupdateenv is not implemented and will always fail
See http://www.open-mpi.org/faq/?category=mpi-apps#override-wrappers-after-v1.0.
Try setting the environmental variable CC to gcc.
csh: setenv CC gcc
bash: export CC=gcc

Resources