Eclipse Makefile: Make Variables are skipped - eclipse

I have a project with a Makefile in it, on Unix console it works fine, compiles, builds and I can run the binary at the end.
I imported the project into Eclipse workspace and somehow Makefile module of Eclipse cannot build the project now. It gives the following error:
g++: error: /src/main: No such file or directory
Whereas there should have been
g++ -I $(APR_INCLUDE) -I $(CMS_HOME)/src/main
which uses two make variables. I already put them before this line and define them as :
export APR_INCLUDE=/usr/include/apr-1
export CMS_HOME=~/Desktop/activemq-cpp-library-3.8.4
Same Makefile is fine with console, but not with Eclipse, which is weird.
Any thoughts?
Here is where I put my export lines:
obstacleDetection_cpp: src/obstacleDetection.cpp protoc_middleman
export APR_INCLUDE=/usr/include/apr-1
export CMS_HOME=~/Desktop/activemq-cpp-library-3.8.4
g++ -I $(APR_INCLUDE) -I $(CMS_HOME)/src/main -g -o src/obstacleDetection.o -c src/obstacleDetection.cpp
cd libs && cp $(CMS_HOME)/src/main/.libs/libactivemq-cpp.so.18.0.4 . && ln -sf libactivemq-cpp.so.18.0.4 libactivemq-cpp.so.18
g++ -L $(CMS_HOME)/src/main/.libs/ -g -o bin/obstacleDetection src/obstacleDetection.o src-gen/Point.pb.cc src-gen/Point.pb.h -lactivemq-cpp -lssl -lprotobuf -pthread
#echo "Success. Run the executable from the binary directory with: LD_LIBRARY_PATH=../libs/ ./obstacleDetection"

This is not right:
obstacleDetection_cpp: src/obstacleDetection.cpp protoc_middleman
export APR_INCLUDE=/usr/include/apr-1
export CMS_HOME=~/Desktop/activemq-cpp-library-3.8.4
g++ $(APR_INCLUDE) -I $(CMS_HOME)/src/main ...
All lines in the recipe (that is, lines that are indented with a TAB in a target context like this) are passed to the shell. These are not make variable assignments. There are two things wrong with that:
First, each logical line in the recipe is passed to a new shell. That means any changes to the process context (such as the environment or the working directory) are present only for the duration of that logical line; once the shell processing that line exits, all those changes are lost. So, these lines have no impact: they set an environment variable in the shell, then the shell exits and that setting is gone.
Second, the variable references you make in your compile line, such as $(APR_INCLUDE), are make variable references, not environment variable references. So even if those environment variable assignments still had effect, they would not be used because you're not referring to environment variables here.
You want to create make variable assignments. That can only be done outside of a recipe. Also, you don't need to export them because only make needs to see them (make will expand them before invoking the shell). So, your makefile should look like this:
APR_INCLUDE = /usr/include/apr-1
CMS_HOME = $(HOME)/Desktop/activemq-cpp-library-3.8.4
obstacleDetection_cpp: src/obstacleDetection.cpp protoc_middleman
g++ -I $(APR_INCLUDE) -I $(CMS_HOME)/src/main -g -o src/obstacleDetection.o -c src/obstacleDetection.cpp
cd libs && cp $(CMS_HOME)/src/main/.libs/libactivemq-cpp.so.18.0.4 . && ln -sf libactivemq-cpp.so.18.0.4 libactivemq-cpp.so.18
g++ -L $(CMS_HOME)/src/main/.libs/ -g -o bin/obstacleDetection src/obstacleDetection.o src-gen/Point.pb.cc src-gen/Point.pb.h -lactivemq-cpp -lssl -lprotobuf -pthread
#echo "Success. Run the executable from the binary directory with: LD_LIBRARY_PATH=../libs/ ./obstacleDetection"

Related

SFML: Unable to run code because of soundbuffer error

I came across a problem that wouldn't let me play sounds on SFML. Whenever I call the sf::SoundBuffer buffer; object, the code would break and spit out an error.
I either think its a problem inside the makefile. Other than that, I'm completely lost in what to do
Sample of makefile:
all: compile link
compile:
g++ -I src/include -c main.cpp
link:
g++ main.o -o Sorter -L src/lib -l sfml-audio -l sfml-graphics -l sfml-window -l sfml-system
Picture of the error

Building postgres from source throws "'utils/errcodes.h' file not found" when called from other makefile

I am currently constructing a Makefile and one of the things it will be doing is downloading and building postgres from source. Before starting to write the makefile file I always used the following set of commands to do this:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3
./configure --prefix "`pwd`" --without-readline --without-zlib
make
make install
Executing the above listed commands in the terminal results in the successful installation of postgres. Then I translated these into a makefile which looks as follows:
build:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3 \
&& ./configure --prefix "`pwd`" --without-readline --without-zlib \
&& $(MAKE) \
&& $(MAKE) install
Running this Makefile results in the error:
../../src/include/utils/elog.h:71:10: fatal error: 'utils/errcodes.h' file not found
It seems that something about calling the make from another Makefile causes a referencing issue with the files during the build process, but I just can figure out for the life of me what I have to change to fix this.
It appears to be the influence of Makefile enviromental variables. I didn't discover the exact mechanism, but unsetting them helps.
build:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
unset MAKELEVEL && unset MAKEFLAGS && unset MFLAGS && cd postgres-REL_13_3 \
&& ./configure --prefix "`pwd`" --without-readline --without-zlib \
&& $(MAKE) \
&& $(MAKE) install

How to edit Makefile to make it work with NetBeans remote build?

I have Makefile like this:
obj-m += some_kernel_module.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
It works when I run make from build machine locally (when my current directory is /home/myaccount/src/some_kernel_module/).
However when I'm trying to compile this remotely in Netbeans I'm getting this error:
/usr/src/linux-headers-3.16.0-6-common/scripts/Makefile.build:44:
/home/myaccount/Makefile: No such file or directory
I guess that's because I have M=$(PWD) in my Makefile, and Netbeans Build Host current directory is my home (/home/myaccount) instead of project directory /home/myaccount/src/some_kernel_module/).
How can I fix that?
I have entered path manually and it works locally and remotely:
obj-m += some_kernel_module.o
all:
make -C /lib/modules/$(shell uname -r)/build M=/home/myaccount/src/some_kernel_module/ modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=/home/myaccount/src/some_kernel_module/ clean
But this is not an answer. I don't want this absolute path in my Makefile.
I found answer here:
How to get current relative directory of your Makefile?
I had to get and store makefile directory like this:
THIS_DIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
And use it instead of PWD (complete Makefile):
obj-m += some_kernel_module.o
THIS_DIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
all:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(THIS_DIR) modules
clean:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(THIS_DIR) clean
Edit: As https://stackoverflow.com/users/939557/madscientist suggested in comments below I changed make to $(MAKE).

rpmbuild no such file or directory

I'm just learning making rpm packages for some custom builds of software that gets compiled from source (some legacy stuff needs this, so I'm trying to learn, as some packages can't use the latest versions), but hitting an error (I'm doing this in Vagrant, and also as root, but typically I'm trying not to use root as I'm aware it has potential for damage, its just this example seems to need some root changes).
sudo rpmbuild -ba testspec.spec --define "_topdir /tmp/"
So far it looks to be using the directory I expected, /tmp/rpmbuild
make[2]: Entering directory `/tmp/rpmbuild/BUILD/exim-4.80.1/build-Linux-x86_64/pdkim'
make[2]: `pdkim.a' is up to date.
make[2]: Leaving directory `/tmp/rpmbu
But then I see these errors...
/usr/lib/rpm/brp-compress: line 8: cd: /tmp/BUILDROOT/custom-exim-4.80.1-1.x86_64: No such file or directory
+ /usr/lib/rpm/brp-strip
find: `/tmp/BUILDROOT/custom-exim-4.80.1-1.x86_64': No such file or directory
+ /usr/lib/rpm/brp-strip-static-archive
find: `/tmp/BUILDROOT/custom-exim-4.80.1-1.x86_64': No such file or directory
+ /usr/lib/rpm/brp-strip-comment-note
So it now seems to be looking in /tmp/BUILDROOT
I'm new to rpmbuild, and don't quite understand some of the process.
My test spec file is at...
%define myversion exim-4.80.1
##%define mybase %{getenv:HOME}
%define mybase /tmp
%define _topdir %{mybase}/rpmbuild
%define _tmppath %{mybase}/rpmbuild/tmp
%define name custom-exim
%define release 1
%define version 4.80.1
%define buildroot %{_topdir}/%{name}-%{version}-root
BuildRoot: %{buildroot}
Summary: %{name}
Name: %{name}
Version: %{version}
Release: %{release}
Source0: ftp://exim.noris.de/exim/exim4/old/exim-4.80.1.tar.gz
License: GPLv1+
Group: Language
AutoReq: no
AutoProv: no
Requires: db4-devel pcre-devel libdb-devel libXt-devel libXaw-devel
%description
Custom Exim Build
%prep
#Do the following manually before building rpm
#mkdir -p /tmp/rpmbuild/BUILD /tmp/rpmbuild/SPECS /tmp/rpmbuild/SOURCES /tmp/rpmbuild/BUILDROOT /tmp/rpmbuild/RPMS /tmp/rpmbuild/SRPMS
#wget ftp://exim.noris.de/exim/exim4/old/exim-4.80.1.tar.gz -O /tmp/rpmbuild/SOURCES/exim-4.80.1.tar.gz
%setup -q -n %{myversion}
grep exim /etc/passwd || useradd -c "Exim" -d /var/spool/exim -m -s /bin/bash exim
%build
# exim needs to config changes before compiling, may do these first and repackage
cp %{mybase}/rpmbuild/BUILD/%{myversion}/src/EDITME %{mybase}/rpmbuild/BUILD/%{myversion}/Local/Makefile
cp %{mybase}/rpmbuild/BUILD/%{myversion}/exim_monitor/EDITME %{mybase}/rpmbuild/BUILD/%{myversion}/Local/eximon.conf
sed -i -e 's/EXIM_USER=$/EXIM_USER=exim/g' "%{mybase}/rpmbuild/BUILD/%{myversion}/Local/Makefile"
sed -i -e 's/LOOKUP_DNSDB=yes/#LOOKUP_DNSDB=yes/g' "%{mybase}/rpmbuild/BUILD/%{myversion}/Local/Makefile"
make
%install
rm -rf $RPM_BUILD_ROOT
#%{__mkdir_p} '%{buildroot}%{_sbindir}'
make install
%clean
rm -rf $RPM_BUILD_ROOT
%post
%postun
%files
Why is it using /tmp/BUILDROOT literally, instead of /tmp/rpmbuild, and are there other obvious things I'm doing wrong ? I've looked at a lot of other tutorials on rpmbuild, but aren't very clear on best practices or what happens during each phase.
Since the buildroot parm is not passed to rpmbuild, the default path is being used by your spec file:
BuildRoot: %{buildroot}
Try adding the buildroot parm... Add buildroot /tmp/rpmbuild to --define
Or if using a makefile:
BUILD_TMP=/tmp/rpmbuild
TOP_DIR=/tmp
rpmbuild -bb
--buildroot $(BUILD_TMP)
--topdir $(TOP_DIR)
$(SPEC_DIR)/testspec.spec
In my case rpm-build was missing.
So sudo yum install rpm-build solved the problem. Or if you use puppet:
package { 'rpm-build':
ensure => latest,
}

I cannot add PATH to PATH file on mac

Here are my .bash_profile and .profile files:
BASH PROFILE
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
export PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH="$HOME/Applications/Postgres.app/Contents/Versions/9.3/bin:$PATH"
#Virtualenvwrapper
export WORKON_HOME=$HOME/Devaus/Envs
export PROJECT_HOME=$HOME/Devaus/Envs
source /usr/local/bin/virtualenvwrapper.sh
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
PROFILE
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
echo $PATH
/Users/User/Devaus/Envs/wsd/bin:/Users/User/.rvm/gems/ruby-2.1.1/bin:/Users/User/.rvm/gems/ruby- 2.1.1#global/bin:/Users/User/.rvm/rubies/ruby- 2.1.1/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/User/.rvm/bin
The question is why /Applications/Postgres.app/Contents/Versions/9.3/bin won't be added to PATH? My goal is to use psqletc commands stated in here http://postgresapp.com/documentation/cli-tools.html
Bash does not automatically read .profile if you have a .bash_profile. Usually this is set up with .bash_profile explicitly loading .profile but you don't seem to have that. Maybe add this to the beginning of your .bash_profile:
test -e ~/.profile && . ~/.profile
Or alternatively put those things in your .bash_profile instead; but then if you need some or all of these settings with /bin/sh you can't do that. It is usually a better arrangement to only have specifically Bash-only code in your .bash_profile and keep your .profile portable to classic Bourne shell (which does not allow export before a variable assignment; so you have syntax error where
export variable=value
should be
variable=value
export variable
instead for portability.)
Incidentally, you only have to export once (andPATH should already be exported by the time Bash runs your personal login files, anyway).