Issue when trying out open GL - c++

I'm new to C++. I'm trying to run a simple example openGL application.
I have downloaded the libraries that are used from the following locations.
http://www.glfw.org/index.html
http://glew.sourceforge.net/
http://glm.g-truc.net/0.9.6/index.html
I am using NetBeans IDE as my C++ IDE. I think I have specified the correct Include Directories because the program compiles without any errors. Following is my include path.
../../../../../gl/glm;../../../../../gl/glew-1.12.0/include;../../../../../gl/glfw-3.1.bin.WIN64/include/GLFW
The command that runs when I compile is the following
CLEAN SUCCESSFUL (total time: 552ms)
C:\MinGW\msys\1.0\bin\make.exe -f nbproject/Makefile-Debug.mk build/Debug/MinGW-Windows/main.o
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/main.o.d"
g++ -c -g -I../../../../../gl/glm -I../../../../../gl/glew-1.12.0/include -I../../../../../gl/glfw-3.1.bin.WIN64/include/GLFW -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.cpp
COMPILE FILE SUCCESSFUL (total time: 4s)
But when running the application I get the following errors.
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/name/Documents/NetBeansProjects/CppApplication_1'
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cppapplication_1.exe
make.exe[2]: Entering directory `/c/Users/name/Documents/NetBeansProjects/CppApplication_1'
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/cppapplication_1 build/Debug/MinGW-Windows/main.o -L../../../../../gl/glfw-3.1.bin.WIN64/lib-mingw -L../../../../../gl/glew-1.12.0/bin/Release/x64
build/Debug/MinGW-Windows/main.o: In function `main':
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:19: undefined reference to `glfwInit'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:25: undefined reference to `glfwWindowHint'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:26: undefined reference to `glfwWindowHint'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:27: undefined reference to `glfwWindowHint'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:28: undefined reference to `glfwWindowHint'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:31: undefined reference to `glfwCreateWindow'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:34: undefined reference to `glfwTerminate'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:37: undefined reference to `glfwMakeContextCurrent'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:40: undefined reference to `_imp__glewInit#0'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:46: undefined reference to `glfwSetInputMode'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:49: undefined reference to `glClearColor#16'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:55: undefined reference to `glfwSwapBuffers'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:56: undefined reference to `glfwPollEvents'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:59: undefined reference to `glfwGetKey'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:60: undefined reference to `glfwWindowShouldClose'
C:\Users\name\Documents\NetBeansProjects\CppApplication_1/main.cpp:63: undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/cppapplication_1.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/name/Documents/NetBeansProjects/CppApplication_1'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/name/Documents/NetBeansProjects/CppApplication_1'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 5s)
Under the Build/Linker section, I have given the following as "Additional Library Directories"
../../../../../gl/glew-1.12.0/lib/Release/x64;../../../../../gl/glfw-3.1.bin.WIN64/lib-mingw
I am using MinGW. What am I doing wrong here?
Update:
I supplied the libaries using the -l option. Now I get another error like the following.
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make.exe[1]: Entering directory `/c/Users/name/Documents/NetBeansProjects/CppApplication_1'
rm -f -r build/Debug
rm -f dist/Debug/MinGW-Windows/cppapplication_1.exe
make.exe[1]: Leaving directory `/c/Users/name/Documents/NetBeansProjects/CppApplication_1'
CLEAN SUCCESSFUL (total time: 1s)
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/name/Documents/NetBeansProjects/CppApplication_1'
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cppapplication_1.exe
make.exe[2]: Entering directory `/c/Users/name/Documents/NetBeansProjects/CppApplication_1'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/main.o.d"
g++ -c -g -I../../../../../gl/glm -I../../../../../gl/glew-1.12.0/include -I../../../../../gl/glfw-3.1.bin.WIN64/include/GLFW -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.cpp
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/cppapplication_1 build/Debug/MinGW-Windows/main.o -L../../../../../gl/glew-1.12.0/bin/Release/x64 -L../../../../../gl/glfw-3.1.bin.WIN64/lib-mingw -lglfw3 -lglew32
../../../../../gl/glew-1.12.0/bin/Release/x64/glew32.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/cppapplication_1.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/name/Documents/NetBeansProjects/CppApplication_1'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/name/Documents/NetBeansProjects/CppApplication_1'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)

Related

How do I avoid getting build failed error in this Fortran Hello World code

PRINT*, 'Hello World'
END
After typing the above in Fortran for the first time, I get the error below. I can't seem to figure out what to do.
cd 'C:\Users\sylvi\Documents\NetBeansProjects\CppApplication_1'
C:\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/sylvi/Documents/NetBeansProjects/CppApplication_1'
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cppapplication_1.exe
make.exe[2]: Entering directory `/c/Users/sylvi/Documents/NetBeansProjects/CppApplication_1'
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/cppapplication_1 build/Debug/MinGW-Windows/main.o build/Debug/MinGW-Windows/testfortran.o
build/Debug/MinGW-Windows/testfortran.o: In function `main':
C:\Users\sylvi\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:2: multiple definition of `main'
build/Debug/MinGW-Windows/main.o:C:\Users\sylvi\Documents\NetBeansProjects\CppApplication_1/main.cpp:21: first defined here
build/Debug/MinGW-Windows/testfortran.o: In function `MAIN__':
C:\Users\sylvi\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:1: undefined reference to `_gfortran_st_write'
C:\Users\sylvi\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:1: undefined reference to `_gfortran_transfer_character_write'
C:\Users\sylvi\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:1: undefined reference to `_gfortran_st_write_done'
build/Debug/MinGW-Windows/testfortran.o: In function `main':
C:\Users\sylvi\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:2: undefined reference to `_gfortran_set_args'
C:\Users\sylvi\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:2: undefined reference to `_gfortran_set_options'
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/cppapplication_1.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/sylvi/Documents/NetBeansProjects/CppApplication_1'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/sylvi/Documents/NetBeansProjects/CppApplication_1'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)

Setting up Netbeans with GMP, how to specify compile options?

I'm trying to use GMP in Netbeans on Windows. The build fails giving the output:
cd 'C:\Users\dev1\Documents\NetBeansProjects\Simple Test'
C:\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/dev1/Documents/NetBeansProjects/Simple Test'
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/simple_test.exe
make.exe[2]: Entering directory `/c/Users/dev1/Documents/NetBeansProjects/Simple Test'
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/simple_test build/Debug/MinGW-Windows/main.o
build/Debug/MinGW-Windows/main.o: In function `ZN17__gmp_binary_plus4evalEP12__mpz_structPKS0_m':
c:/mingw/include/gmpxx.h:196: undefined reference to `__gmpz_add_ui'
build/Debug/MinGW-Windows/main.o: In function
c:/mingw/include/gmpxx.h:1497: undefined reference to `__gmpz_init'
//...same thing
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/simple_test.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/dev1/Documents/NetBeansProjects/Simple Test'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/dev1/Documents/NetBeansProjects/Simple Test'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
Here are the settings I changed in Netbeans and guess where the error lies
How can I get GMP to work so I can use it in my source code?
It's definitely a setting on Netbeans as I can compile it from the command line with g++ test.cpp -o test.exe -lgmpxx -lgmp
Got this answer from mathGl / MinGW undefined reference Netbeans IDE
right click on project and go to properties
in the left pane select linker
click the "..." beside libraries
click "add option"
select "other option" and type in -lgmpxx -lgmp
click ok
Should now see...

opengl cannot find libraries in mingw compiler netbeans

cd 'C:\Users\Deepa\Documents\NetBeansProjects\game' C:\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug "/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/Deepa/Documents/NetBeansProjects/game' "/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/game.exe
make.exe[2]: Entering directory `/c/Users/Deepa/Documents/NetBeansProjects/game'
mkdir -p build/Debug/MinGW-Windows
g++ -c -g -s -o build/Debug/MinGW-Windows/main.o main.cpp
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/game build/Debug/MinGW-Windows/main.o -lglew32 -lglew32s -lglut32
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lglew32s
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lglut32
collect2: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/game.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/Deepa/Documents/NetBeansProjects/game'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/Deepa/Documents/NetBeansProjects/game'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 6s)
im using a minGW compiler but " /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lglew32s " it seems to be in cygwin..
why is it so? and i cant build the file help please

c++ libtins build error

I'm attempting the litbins build packet example over at http://libtins.github.io.
I've followed the install instructions and am able to #include <tins/tins.h> just fine. The problem seems to be now in actually referencing its functions. When trying to build this class:
#include <tins/tins.h>
#include <cassert>
#include <iostream>
#include <string>
using namespace Tins;
int main() {
NetworkInterface iface = NetworkInterface::default_interface();
NetworkInterface::Info info = iface.addresses();
EthernetII eth("77:22:33:11:ad:ad", info.hw_addr);
eth /= IP("localhost", info.ip_addr);
eth /= TCP(13, 15);
eth /= RawPDU("I'm a payload!");
PacketSender sender;
sender.send(eth, iface);
}
I get this error:
cd '/home/oisin/NetBeansProjects/TCPPacket'
/usr/bin/gmake -f Makefile CONF=Debug
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
gmake[1]: Entering directory '/home/oisin/NetBeansProjects/TCPPacket'
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/tcppacket
gmake[2]: Entering directory '/home/oisin/NetBeansProjects/TCPPacket'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/tcppacket build/Debug/GNU-Linux/main.o
build/Debug/GNU-Linux/main.o: In function `main':
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:26: undefined reference to `Tins::NetworkInterface::default_interface()'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:28: undefined reference to `Tins::NetworkInterface::addresses() const'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:30: undefined reference to `Tins::EthernetII::EthernetII(Tins::HWAddress<6ul, unsigned char> const&, Tins::HWAddress<6ul, unsigned char> const&)'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:32: undefined reference to `Tins::IPv4Address::IPv4Address(char const*)'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:32: undefined reference to `Tins::IP::IP(Tins::IPv4Address, Tins::IPv4Address)'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:34: undefined reference to `Tins::TCP::TCP(unsigned short, unsigned short)'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:36: undefined reference to `Tins::RawPDU::RawPDU(std::string const&)'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:38: undefined reference to `Tins::PacketSender::DEFAULT_TIMEOUT'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:38: undefined reference to `Tins::NetworkInterface::NetworkInterface()'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:38: undefined reference to `Tins::PacketSender::PacketSender(Tins::NetworkInterface const&, unsigned int, unsigned int)'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:40: undefined reference to `Tins::PacketSender::send(Tins::PDU&, Tins::NetworkInterface const&)'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:38: undefined reference to `Tins::PacketSender::~PacketSender()'
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:38: undefined reference to `Tins::PacketSender::~PacketSender()'
build/Debug/GNU-Linux/main.o: In function `Tins::EthernetII& Tins::operator/=<Tins::EthernetII>(Tins::EthernetII&, Tins::PDU const&)':
/usr/local/include/tins/pdu.h:537: undefined reference to `Tins::PDU::inner_pdu(Tins::PDU*)'
build/Debug/GNU-Linux/main.o: In function `Tins::EthernetII::~EthernetII()':
/usr/local/include/tins/ethernetII.h:46: undefined reference to `vtable for Tins::EthernetII'
/usr/local/include/tins/ethernetII.h:46: undefined reference to `Tins::PDU::~PDU()'
build/Debug/GNU-Linux/main.o: In function `Tins::IP::~IP()':
/usr/local/include/tins/ip.h:64: undefined reference to `vtable for Tins::IP'
/usr/local/include/tins/ip.h:64: undefined reference to `Tins::PDU::~PDU()'
build/Debug/GNU-Linux/main.o: In function `Tins::TCP::~TCP()':
/usr/local/include/tins/tcp.h:79: undefined reference to `vtable for Tins::TCP'
/usr/local/include/tins/tcp.h:79: undefined reference to `Tins::PDU::~PDU()'
build/Debug/GNU-Linux/main.o: In function `Tins::RawPDU::~RawPDU()':
/usr/local/include/tins/rawpdu.h:64: undefined reference to `vtable for Tins::RawPDU'
/usr/local/include/tins/rawpdu.h:64: undefined reference to `Tins::PDU::~PDU()'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/GNU-Linux/tcppacket' failed
gmake[2]: *** [dist/Debug/GNU-Linux/tcppacket] Error 1
gmake[2]: Leaving directory '/home/oisin/NetBeansProjects/TCPPacket'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
gmake[1]: *** [.build-conf] Error 2
gmake[1]: Leaving directory '/home/oisin/NetBeansProjects/TCPPacket'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
gmake: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
Netbeans is using c++11 , I've enabled c++11 support with the -DLIBTINS_ENABLE_CXX11=1 and I've run ldconfig along with restarting the VM, same errors.
I've tried linking the class with g++ main.cpp -o main -ltins to get these errors -
In file included from /usr/local/include/tins/tins.h:60:0,
from main.cpp:14:
/usr/local/include/tins/crypto.h:297:13: error: ‘function’ in namespace ‘std’ does not name a type
typedef std::function<void(const std::string&,
^
/usr/local/include/tins/crypto.h:308:13: error: ‘function’ in namespace ‘std’ does not name a type
typedef std::function<void(const std::string&,
^
/usr/local/include/tins/crypto.h:401:44: error: ‘handshake_captured_callback_type’ does not name a type
void handshake_captured_callback(const handshake_captured_callback_type& callback);
^
/usr/local/include/tins/crypto.h:412:34: error: ‘ap_found_callback_type’ does not name a type
void ap_found_callback(const ap_found_callback_type& callback);
^
/usr/local/include/tins/crypto.h:445:9: error: ‘handshake_captured_callback_type’ does not name a type
handshake_captured_callback_type handshake_captured_callback_;
^
/usr/local/include/tins/crypto.h:446:9: error: ‘ap_found_callback_type’ does not name a type
ap_found_callback_type ap_found_callback_;
^
Help appreciated.
EDIT
Following on from dvnguyen's answer below, linking my main.cpp with g++ app.cpp -o app -ltins -std=c++11 solved the above issues, but now I'm left with the following errors -
cd '/home/oisin/NetBeansProjects/TCPPacket'
/usr/bin/gmake -f Makefile CONF=Debug
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
gmake[1]: Entering directory '/home/oisin/NetBeansProjects/TCPPacket'
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/tcppacket
gmake[2]: Entering directory '/home/oisin/NetBeansProjects/TCPPacket'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/tcppacket build/Debug/GNU-Linux/main.o -lmain
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lmain
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/GNU-Linux/tcppacket' failed
gmake[2]: *** [dist/Debug/GNU-Linux/tcppacket] Error 1
gmake[2]: Leaving directory '/home/oisin/NetBeansProjects/TCPPacket'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
gmake[1]: *** [.build-conf] Error 2
gmake[1]: Leaving directory '/home/oisin/NetBeansProjects/TCPPacket'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
gmake: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
I'm really clueless as to what I'm missing.
From the undefined reference message in the error log I can tell that you haven't added/linked the lib to your project. I don't know about your Netbean project setting, but if your use gcc, you can see an example here:
g++ app.cpp -o app -ltins -std=c++11

undefined reference to `gnuplot_init()'

I'm trying to use gnuplot_i, a gnuplot interface for ANSI-C, for my C++ project. (See here in the download section)
It seems to just consist of one header and one source file. The Makefile just creates an object file, so I decided to completely integrate those two files in my project. However I'm getting errors of undefined references to functions that are implemented in aforementioned source file.
Consider the following simplified example (main.cpp):
#include <gnuplot_i.h>
int main(int argc, char** argv) {
gnuplot_ctrl * h;
h = gnuplot_init();
return 0;
}
The header file can be obtained here and the source file here.
The error I get is the following:
build/Debug/GNU-Linux/main.o: In function `main':
/<some path>/proj/test/main.cpp:18: undefined reference to `gnuplot_init()'
collect2: error: ld returned 1 exit status
However gnuplot_init() is implemented in the source file which gets compiled to an object file which is then used to link the program. You can see this in the full log below. Also the generated object file contains the necessary symbol:
$ nm gnuplot_i.o | grep gnuplot_init
0000000000000000 T gnuplot_init
full log:
cd '/<some path>/proj/test'
/usr/bin/make -f Makefile CONF=Debug clean
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory '/<some path>/proj/test'
rm -f -r build/Debug
rm -f dist/Debug/GNU-Linux/test
make[1]: Leaving directory '/<some path>/proj/test'
CLEAN SUCCESSFUL (total time: 52ms)
cd '/<some path>/proj/test'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/<some path>/proj/test'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/test
make[2]: Entering directory '/<some path>/proj/test'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/gnuplot_i.o.d"
gcc -c -g -I. -MMD -MP -MF "build/Debug/GNU-Linux/gnuplot_i.o.d" -o build/Debug/GNU-Linux/gnuplot_i.o gnuplot_i.c
gnuplot_i.c: In function ‘gnuplot_tmpfile’:
gnuplot_i.c:696:5: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
close(unx_fd);
^~~~~
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++ -c -g -I. -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/test build/Debug/GNU-Linux/gnuplot_i.o build/Debug/GNU-Linux/main.o
build/Debug/GNU-Linux/main.o: In function `main':
/<some path>/proj/test/main.cpp:18: undefined reference to `gnuplot_init()'
collect2: error: ld returned 1 exit status
make[2]: *** [nbproject/Makefile-Debug.mk:64: dist/Debug/GNU-Linux/test] Error 1
make[2]: Leaving directory '/<some path>/proj/test'
make[1]: *** [nbproject/Makefile-Debug.mk:60: .build-conf] Error 2
make[1]: Leaving directory '/<some path>/proj/test'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2
BUILD FAILED (exit value 2, total time: 304ms)
As I'm using an auto-generated buildsystem from NetBeans the Makefiles are quite big and complex. But it should be pretty obvious from the log which commands have been issued. What is exactly wrong here? Is it a problem that I link C-Object files and C++-Object files? From my understanding it shouldn't.
Well the answer came to me the moment I pressed send.
I'm obviously missing an extern "C"
extern "C" {
#include <gnuplot_i.h>
}
int main(int argc, char** argv) {
gnuplot_ctrl * h;
h = gnuplot_init();
return 0;
}