Error: Compiling simple PjSIP program under ubuntu - c++

I am trying to compile simple PjSIP program under ubuntu. I am getting error as
/usr/bin/ld: cannot find -lpjsua-i686-pc-linux-gnu
What does it mean?
Here is the ouput:-
root#mypc-desktop:/home/mypc/pjsip# make
gcc -o myapp myapp.cpp -DPJ_AUTOCONF=1 -O2 -I/home/mypc/pjproject-1.4.5/pjlib/include -I/home/mypc/pjproject-1.4.5/pjlib-util/include -I/home/mypc/pjproject-1.4.5/pjnath/include -I/home/mypc/pjproject-1.4.5/pjmedia/include -I/home/mypc/pjproject-1.4.5/pjsip/include -L/home/mypc/pjproject-1.4.5/pjlib/lib -L/home/mypc/pjproject-1.4.5/pjlib-util/lib -L/home/mypc/pjproject-1.4.5/pjnath/lib -L/home/mypc/pjproject-1.4.5/pjmedia/lib -L/home/mypc/pjproject-1.4.5/pjsip/lib -L/home/mypc/pjproject-1.4.5/third_party/lib -lpjsua-i686-pc-linux-gnu -lpjsip-ua-i686-pc-linux-gnu -lpjsip-simple-i686-pc-linux-gnu -lpjsip-i686-pc-linux-gnu -lpjmedia-codec-i686-pc-linux-gnu -lpjmedia-i686-pc-linux-gnu -lpjmedia-audiodev-i686-pc-linux-gnu -lpjnath-i686-pc-linux-gnu -lpjlib-util-i686-pc-linux-gnu -lresample-i686-pc-linux-gnu -lmilenage-i686-pc-linux-gnu -lsrtp-i686-pc-linux-gnu -lgsmcodec-i686-pc-linux-gnu -lspeex-i686-pc-linux-gnu -lilbccodec-i686-pc-linux-gnu -lg7221codec-i686-pc-linux-gnu -lportaudio-i686-pc-linux-gnu -lpj-i686-pc-linux-gnu -lm -lnsl -lrt -lpthread
/usr/bin/ld: cannot find -lpjsua-i686-pc-linux-gnu
collect2: ld returned 1 exit status
make: *** [myapp] Error 1
Here is code
#include <pjlib.h>
#include <pjlib-util.h>
#include <pjmedia.h>
#include <pjmedia-codec.h>
#include <pjsip.h>
#include <pjsip_simple.h>
#include <pjsip_ua.h>
#include <pjsua-lib/pjsua.h>
int main()
{
return 0;
}
Here is a Makefile
#Modify this to point to the PJSIP location.
PJBASE=/home/mypc/pjproject-1.4.5
include $(PJBASE)/build.mak
CC = $(APP_CC)
LDFLAGS = $(APP_LDFLAGS)
LDLIBS = $(APP_LDLIBS)
CFLAGS = $(APP_CFLAGS)
CPPFLAGS= ${CFLAGS}
# If your application is in a file named myapp.cpp or myapp.c
# this is the line you will need to build the binary.
all: myapp
myapp: myapp.cpp
$(CC) -o $# $< $(CPPFLAGS) $(LDFLAGS) $(LDLIBS)
clean:
rm -f myapp.o myapp
Thanks
EDIT:
I just noticed that there is a error building PjSIP
make[2]: Entering directory
/home/mypc/pjproject-1.4.5/pjnath/build'
gcc -c -Wall -DPJ_AUTOCONF=1 -O2
-Wno-unused-label -Werror -I../include -I../../pjlib/include -I../../pjlib-util/include \ -o output/pjnath-i686-pc-linux-gnu/stun_session.o
\ ../src/pjnath/stun_session.c cc1:
warnings being treated as errors
../src/pjnath/stun_session.c: In
function ‘apply_msg_options’:
../src/pjnath/stun_session.c:230:
error: suggest parentheses around &&
within || make[2]: ***
[output/pjnath-i686-pc-linux-gnu/stun_session.o]
Error 1 make[2]: Leaving directory
/home/mypc/pjproject-1.4.5/pjnath/build'
make[1]: * [pjnath] Error 2 make[1]:
Leaving directory
`/home/mypc/pjproject-1.4.5/pjnath/build'
make: * [all] Error 1
When I tried to find -Werror in make files present at /home/mypc/pjproject-1.4.5/pjnath/build, $(PJDIR)/build.mak and $(PJDIR)/build/common.mak its not present there anybody know where it could be ?

It seems that the pj* can't build the neccessary libaries - for a simple fix try to locate the line in /home/mypc/pjproject-1.4.5/build.mak where -Werror is added to $(APP_CFLAGS) and remove it (the -Werror, not the whole line if other flags are added :).
Alternatively apply the fix suggested by gcc on line 230 in src/pjnath/stun_session.c.
edit:
Just read that you found no -Werror. Could you either paste line 230 of stun_session.c or the make-files somewhere?
The source line would be preferred.

Related

Compile *.cpp and *.c with Automake

Structure:
-myProject
-Makefile.am
-configure.ac
-src
-Makefile.am
-main.c
-test.c
-test.h
When I try to compile, I've got the error Undefinded reference to a function from test.c.
Makefile.am:
AUTOMAKE_OPTIONS = foreign
SUBDIRS=src
src/Makefile.am:
bin_PROGRAMS = TEST
AM_CXXFLAGS =-Wall -Wno-psabi -w -pthread -I/usr/local/include
AM_CFLAGS =-Wall -w
#Sources
TEST_SOURCES = test.c main.cpp
TEST_LDADD = #LDFLAGS# -lmosquitto
TEST_LDFLAGS =-lmosquitto
It seem's, that it's not possible to linkt the two sources. Can anybody help me??
ERROR:
make all-recursive
make[1]: Entering directory '/media/sf_Shared/Software/executables/TEST'
Making all in src
make[2]: Entering directory '/media/sf_Shared/Software/executables/TEST/src'
g++ -DHAVE_CONFIG_H -I. -I.. -Wall -Wno-psabi -w -pthread -I/usr/local/include -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.cpp
mv -f .deps/main.Tpo .deps/main.Po
g++ -Wall -Wno-psabi -w -pthread -I/usr/local/include -g -O2 -lmosquitto -o TEST test.o main.o -lmosquitto
/usr/bin/ld: main.o: in function `main':
/media/sf_Shared/Software/executables/TEST/src/main.cpp:564: undefined reference to `open_ports(unsigned int, unsigned int)'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:366: TEST] Error 1
make[2]: Leaving directory '/media/sf_Shared/Software/executables/TEST/src'
make[1]: *** [Makefile:359: all-recursive] Error 1
make[1]: Leaving directory '/media/sf_Shared/Software/executables/TEST'
make: *** [Makefile:300: all] Error 2
I'm including in the main.cpp the test.h. There is the function open_ports declared(u_int32_t open_ports(u_int32_t a, u_int32_t b);), which is implemented in test.c
This is not an automake issue — you are doing the right thing (or at least close to) in the Makefile.am.
The problem is that your symbol is declared without extern "C", but defined only in C, so when the C++ compiler takes your main.cpp, it expects to find a mangled symbols (which encodes the signature of the function, that is the number and types of parameters), rather than a plain (C) one.
You can tell that this is the case because it's looking for open_ports(unsigned int, unsigned int) — rather than just open_ports.
The easiest solution is to change your main.cpp to say:
extern "C" {
#include "test.h"
}
That declares that the test.h header only includes C declarations, which will then generate the right symbol lookup for what you define in test.c.

Error in in linking makefile (exit code 1)

This is my first time using makefile. I am getting "linker command failed with exit code 1 " error while using "clang".
I just linked .h files in makefile and run make all in ubuntu teminal.
CC_EXEC = clang
CC_FLAGS = -g
CC = ${CC_EXEC} ${CC_FLAGS}
BUILD_DIR = build
all: executable.out
executable.out: ${BUILD_DIR}/main.o ${BUILD_DIR}/UTrelloInterface.o ${BUILD_DIR}/User.o ${BUILD_DIR}/List.o ${BUILD_DIR}/Task.o
clang -g ${BUILD_DIR}/main.o ${BUILD_DIR}/UTrelloInterface.o ${BUILD_DIR}/User.o ${BUILD_DIR}/List.o ${BUILD_DIR}/Task.o -o ${BUILD_DIR}/executable.out
${BUILD_DIR}/main.o: main.cpp UTrelloInterface.h User.h List.h Task.h
${CC} -c main.cpp -o ${BUILD_DIR}/main.o
${BUILD_DIR}/User.o: User.cpp User.h
${CC} -c User.cpp -o ${BUILD_DIR}/User.o
${BUILD_DIR}/List.o: List.cpp List.h
${CC} -c List.cpp -o ${BUILD_DIR}/List.o
${BUILD_DIR}/Task.o: Task.cpp Task.h
${CC} -c Task.cpp -o ${BUILD_DIR}/Task.o
${BUILD_DIR}/UTrelloInterface.o: UTrelloInterface.cpp UTrelloInterface.h Task.h List.h User.h
${CC} -c UTrelloInterface.cpp -o ${BUILD_DIR}/UTrelloInterface.o
.PHONY: clean
clean:
rm -rf build/ && mkdir -p build
I got exactly this error:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
makefile:11: recipe for target 'executable.out' failed
make: *** [executable.out] Error 1
I got this error while using g++ compiler:
g++ -g -c User.cpp -o build/User.o
g++ -g build/main.o build/UTrelloInterface.o build/User.o build/List.o build/Task.o -o build/executable.out
/usr/bin/ld: build/main.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
makefile:11: recipe for target 'executable.out' failed
make: *** [executable.out] Error 1
What should I do?

Using gcc with Netbeans

I want to learn to use shaders and therefore created a new C++ project on Netbeans (ver. 8.0.2).
I want to include the GLFW and the GLEW Library like stated in this tutorial: http://www.learnopengl.com/#!Getting-started/Creating-a-window
I think i included the librarys successfully. (Netbeans shows no error when using #include <GL\glew.h> or #include <GLFW\glfw3.h>, so i think it finds all the files).
My System: Windows 10 x64, using GNU gcc compiler via cygwin
Now here is the problem:
When i try to run the program, there is the following output:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/Erik/programming/projects/FinallyShaders'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/finallyshaders.exe
make[2]: Entering directory '/cygdrive/c/Users/Erik/programming/projects/FinallyShaders'
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/main.o.d"
gcc -c -g -include /cygdrive/C/Users/Erik/programming/Libraries/glew-1.13.0-win32/glew-1.13.0/include/GL -include /cygdrive/C/Users/Erik/programming/Libraries/glfw-3.1.2.bin.WIN32/glfw-3.1.2.bin.WIN32/include/GLFW -MMD -MP -MF "build/Debug/Cygwin-Windows/main.o.d" -o build/Debug/Cygwin-Windows/main.o main.c
cc1: fatal error: /cygdrive/C/Users/Erik/programming/Libraries/glew-1.13.0-win32/glew-1.13.0/include/GL: No such file or directory
compilation terminated.
nbproject/Makefile-Debug.mk:66: recipe for target 'build/Debug/Cygwin-Windows/main.o' failed
make[2]: *** [build/Debug/Cygwin-Windows/main.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/Erik/programming/projects/FinallyShaders'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/Erik/programming/projects/FinallyShaders'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 722ms)
It seems to fail because the gcc compiler (or more precisely the cc1 part of it) can't find the include-directory for the library. But, as stated, the path is correct. When using cd <the path that cannot be found> everything works and cygwin finds this path.
(My program does nothing but calling printf() until now, that shouldn't be the problem)
Does anybody know what this could mean and how to solve this?
Thanks for your help
Erik Brendel
Your failing compiler commandline is:
gcc -c -g \
-include /cygdrive/C/Users/Erik/programming/Libraries/glew-1.13.0-win32/glew-1.13.0/include/GL \
-include /cygdrive/C/Users/Erik/programming/Libraries/glfw-3.1.2.bin.WIN32/glfw-3.1.2.bin.WIN32/include/GLFW \
-MMD -MP -MF "build/Debug/Cygwin-Windows/main.o.d" \
-o build/Debug/Cygwin-Windows/main.o main.c
To fix the reported error:
cc1: fatal error: /cygdrive/C/Users/Erik/programming/Libraries/glew-1.13.0-win32/glew-1.13.0/include/GL: No such file or directory
it should be:
gcc -c -g \
-I/cygdrive/C/Users/Erik/programming/Libraries/glew-1.13.0-win32/glew-1.13.0/include/GL \
-I/cygdrive/C/Users/Erik/programming/Libraries/glfw-3.1.2.bin.WIN32/glfw-3.1.2.bin.WIN32/include/GLFW \
-MMD -MP -MF "build/Debug/Cygwin-Windows/main.o.d" \
-o build/Debug/Cygwin-Windows/main.o main.c
You have confused the compiler options -include and -I. See the documentation of
these options
Here is a pretty good introductory tutorial to the use of GCC
In the Netbeans project properties, the include search-directories should be
entered in Build -> C Compiler -> Include Directories, not Include Headers.
Are you configuring the proyect linker for Netbeans?? This means telling the IDE you will be using libraries that are not added by default with just the include command, for example the math.h library(remember you had to compile with -lm via command promp, it's the same thing).
This can be done by going to run-proyect configuration-customize-Linker-Libraries(you click on the button with says ...).
Then you click on add pkgconfig library or standard(for something like math.h or pthread in unix systems), and search for the library you wish to add.

How can I connect modules?

So, I am trying to write Makefile.am that will check the source code and the dependencies for the build.
configure.in
AC_PREREQ([2.68])
AC_INIT([hello], [1.0], [basinbug at yahoo.com])
AC_CONFIG_SRCDIR([src/hello.cpp])
AM_INIT_AUTOMAKE
AC_PROG_CXX
PKG_CHECK_MODULES([GTK], [gtk+-2.0 >= 2.10])
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
src/Makefile.am
bin_PROGRAMS = hello
hello_CFLAGS = $(GTK_CFLAGS)
hello_LDFLAGS = $(GTK_LIBS)
hello_SOURCES = hello.cpp
what happens when i run "make"
Making all in src
make[1]: Entering directory `/home/maza/123/src'
g++ -DPACKAGE_NAME=\"hello\" -DPACKAGE_TARNAME=\"hello\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"hello\ 1.0\" -DPACKAGE_BUGREPORT=\"basinbug\ at\ yahoo.com\" -DPACKAGE_URL=\"\" -DPACKAGE=\"hello\" -DVERSION=\"1.0\" -I. -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.cpp
hello.cpp:2:21: fatal error: gtk/gtk.h: No such file or directory
compilation terminated.
make[1]: *** [hello.o] Error 1
make[1]: Leaving directory `/home/maza/123/src'
make: *** [all-recursive] Error 1
If I'm going as AC_PROG_CC, they are used for compile the string, through AC_PROG_CXX it is not used
You are telling the autotools that your project is a C++ project (with AC_PROG_CXX) but you are then setting a C flag variable (hello_CFLAGS).
The matching variable for C++ is hello_CXXFLAGS.
That being said neither of those is the correct flag to use for this usage. The correct flag (thanks ptomato) is hello_CPPFLAGS.

Linking Error While using liboauth . Getting Error undefined reference to `oauth_url_escape'

I am getting linking error when I am using liboauth
code id
#include <cstdlib>
#include<oauth.h>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
oauth_url_escape("vivek");
return 0;
}
Makefile is auto generated by Netbeans which is
MKDIR=mkdir
CP=cp
GREP=grep
NM=nm
CCADMIN=CCadmin
RANLIB=ranlib
CC=gcc
CCC=g++
CXX=g++
FC=gfortran
AS=as
# Macros
CND_PLATFORM=GNU-Linux-x86
CND_CONF=Debug
CND_DISTDIR=dist
# Include project Makefile
include Makefile
# Object Directory
OBJECTDIR=build/${CND_CONF}/${CND_PLATFORM}
# Object Files
OBJECTFILES= \
${OBJECTDIR}/main.o
# C Compiler Flags
CFLAGS=
# CC Compiler Flags
CCFLAGS=
CXXFLAGS=
# Fortran Compiler Flags
FFLAGS=
# Assembler Flags
ASFLAGS=
# Link Libraries and Options
LDLIBSOPTIONS=-loauth
# Build Targets
.build-conf: ${BUILD_SUBPROJECTS}
"${MAKE}" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/cppapplication_4
dist/Debug/GNU-Linux-x86/cppapplication_4: ${OBJECTFILES}
${MKDIR} -p dist/Debug/GNU-Linux-x86
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cppapplication_4 ${OBJECTFILES} ${LDLIBSOPTIONS}
${OBJECTDIR}/main.o: main.cpp
${MKDIR} -p ${OBJECTDIR}
${RM} $#.d
$(COMPILE.cc) -g -I../../Desktop/code_try/trunk/lib/out/linux/release64/liboauth-0.9.4/src -MMD -MP -MF $#.d -o ${OBJECTDIR}/main.o main.cpp
# Subprojects
.build-subprojects:
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r build/Debug
${RM} dist/Debug/GNU-Linux-x86/cppapplication_4
# Subprojects
.clean-subprojects:
# Enable dependency checking
.dep.inc: .depcheck-impl
include .dep.inc
I am getting error code
g++ -o dist/Debug/GNU-Linux-x86/cppapplication_4 build/Debug/GNU-Linux-x86/main.o ../../Desktop/cm_try/trunk/lib/out/linux/release64/sqlite/liboauth.a
build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/vivek/NetBeansProjects/CppApplication_4/main.cpp:16: undefined reference to `oauth_url_escape(char const*)'
collect2: ld returned 1 exit status
gmake[2]: *** [dist/Debug/GNU-Linux-x86/cppapplication_4] Error 1
gmake[1]: *** [.build-conf] Error 2
gmake: *** [.build-impl] Error 2
gmake[2]: Leaving directory `/home/vivek/NetBeansProjects/CppApplication_4'
gmake[1]: Leaving directory `/home/vivek/NetBeansProjects/CppApplication_4
'
We just need to change include statement in C++ code
extern "C" {
#include <oauth.h>
}