Freeglut 64 bit program linking errors - c++

I'm trying to compile a 64 bit version of an OpenGL C++ program using freeglut. I followed the exact instructions on this website to set up freeglut with MinGW. I have the header files in C:\MinGW\include\GL, I have the 32 bit libraries in C:\MinGW\lib and 64 bit libraries in C:\MinGW\lib\x64, and I have the 64 bit freeglut.dll in my project directory. However, even the simplest of OpenGL programs don't link successfully...
My code is minimal:
// test.cpp
#include <GL/glut.h>
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
}
And I compile it with the exact commands given on the readme/on the website:
g++ -c -o test.o test.cpp -I"C:\MinGW\include"
g++ -o test.exe test.o -L"C:\MinGW\lib\x64" -lfreeglut -lopengl32 -Wl,--subsystem,windows
(except of course I changed the directories and changed gcc to g++)
The compile runs fine, but linking throws these error messages:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: test.o:test.cpp:(.text+0x1c): undefined reference to `_imp____glutInitWithExit#12'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: test.o:test.cpp:(.text+0x3f): undefined reference to `_imp____glutCreateWindowWithExit#8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: test.o:test.cpp:(.text+0x61): undefined reference to `_imp____glutCreateMenuWithExit#8'
collect2.exe: error: ld returned 1 exit status
I've tried to change -lopengl32 in the command to -lopengl64 and -lopengl, but the linker couldn't find those libraries.

I can't answer your specific case, but another approach would be to use mingw-w64, with MSYS2 as a package manager. The old mingw.org project is not well maintained, unlike mingw-w64 and the MSYS2 package database. There is probably some mismatch between how your precompiled binaries were built and the compiler you are currently using.
On my system I compiled your code with g++ -o gl gl.cpp -lfreeglut and it worked first time .
How to install MinGW-w64 and MSYS2?
Then use pacman -Ss glut to find the freeglut package.

Related

libtensorflow_core.a missing symbols (tensorflow::port::InitMain(char const*, int*, char***)

I have compiled the static library libtensorflow_core.a in the tensorflow/contrib/makefiles/gen/lib folder using the
./tensorflow/contrib/makefile/build_all_linux.sh
script
Making some minor adjustments for CentOS 6.10 to include a LD_LIBRARY_PATH for libstdc++ as the gcc that comes with CentOS 6 is gcc 4.4 and gcc 4.8 is needed for C++11
I have tested the compile was successful by testing the benchmark binary with my model
./tensorflow/contrib/makefile/gen/bin/benchmark etc
This all works as expected.
Now I am hosting Tensorflow in my application, which was previously dynamically linked to libtensorflow_cc.so and libtensorflow_framework.so
instead I am linking to libtensorflow_core.a statically
Compiling and linking of my plugin are successful.
At runtime the following error occurs:
/usr/local/Nuke11.3v1/Nuke11.3: symbol lookup error: /usr/OFX/Plugins/rotobot.ofx.bundle/Contents/Linux-x86-64/rotobot.ofx: undefined symbol: _ZN10tensorflow4port8InitMainEPKcPiPPPc
We can see the symbol missing is
tensorflow::port::InitMain(char const*, int*, char***)
my code indeed contains this function
[samh#apollo-centos6 Rotobot-CPU-static]$ grep -rn InitMain rotobot.cpp
130: tensorflow::port::InitMain(&usage[0], &argc, NULL);
What adjustments do I need to make to my the libtensorflow_core.a Makefile to include InitMain?
Sam
I can see that this function is in the benchmark binary which works
and I can also see that the benchmark source are as follows
BENCHMARK_SRCS := \
tensorflow/core/util/reporter.cc \
tensorflow/tools/benchmark/benchmark_model.cc \
tensorflow/tools/benchmark/benchmark_model_main.cc
the LIBS flags for my compile are the libprotobuf.a and libtensorflow_core.a and the other things needed for my application
I think if you had the following
#include <tensorflow/core/platform/init_main.h>
#include <tensorflow/core/public/session.h>
int main(int argc, char* argv[]){
char usage[] = "iLikeTurtles";
tensorflow::port::InitMain(&usage[0], &argc, NULL);
}
it would be enough to trigger the error
I would expect the program to function the same as the code linked against libtensorflow_cc.so and libtensorflow_framework.so
looking into
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/benchmark/BUILD
deps = select({
"//tensorflow:android": [
"//tensorflow/core:android_tensorflow_lib",
"//tensorflow/core:android_tensorflow_test_lib",
],
"//conditions:default": [
"//tensorflow/core:core_cpu",
"//tensorflow/core:lib",
"//tensorflow/core:framework",
"//tensorflow/core:framework_internal",
"//tensorflow/core:framework_lite",
"//tensorflow/core:protos_all_cc",
"//tensorflow/core:tensorflow",
"//tensorflow/core:test",
],
}),
Looks like we might need the .o files for framework, framework_internal, and framework_lite.
the devil is in the detail
here are the library args to use the static library
-Wall -L$(TENSORFLOW)/tensorflow/contrib/makefile/gen/protobuf-host/lib -Wl,--allow-multiple-definition -Wl,--whole-archive $(TENSORFLOW)/tensorflow/contrib/makefile/gen/lib/libtensorflow-core.a -Wl,--no-whole-archive $(TENSORFLOW)/tensorflow/contrib/makefile/downloads/nsync/builds/default.linux.c++11/nsync.a -lstdc++ -l:libprotobuf.a -lz -lm -ldl -lpthread -lrt
Then everything works great
This was deciphered by looking at make VERBOSE=true when executing the build_all_linux.sh
and looking at the last command for building and linking the benchmark executable
you may not need -lrt but I do on CentOS 6.10
I still need to do the same on OSX
Building on OSX is still using the build_all_linux.sh script as OSX is close enough to Linux
TENSORFLOW_LIBS = -Wl,-force_load,$(TENSORFLOW)/tensorflow/contrib/makefile/gen/lib/libtensorflow-core.a -Wl,-force_load,$(TENSORFLOW)/tensorflow/contrib/makefile/downloads/nsync/builds/default.macos.c++11/nsync.a -Wl,-force_load,$(TENSORFLOW)/tensorflow/contrib/makefile/gen/protobuf-host/lib/libprotobuf.a -lstdc++ -lz -lpthread

gtest and MinGW linkage

I've made a simple main to check if gtest was correctly linked and got "undefined reference" errors. The first line in the main function throws an undefined reference to `testing::InitGoogleTest(int*, char**)'.
#include <gtest/gtest.h>
int main(int argc, char* argv[])
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
I have successfully built a gtest Code::Block project with the help of cmake and without the pthread library. Then, I compiled everything with MinGW. I took the libgtest.a libgmock.a and linked them in my Code::Block project with no problems. I also specified the include directories and the binary directories. Is it possible that I need to include gtest_main.a too?
The build log (I added "..." to hide long chains of folders):
"obj\Debug gtest\MainTest.o" -lsfml-graphics-s-d -lsfml-window-s-d -lsfml-network-s-d -lsfml-audio-s-d -lsfml-system-s-d -lglew -lgtest -lgmock -lws2_32 -lopenal32 -lsndfile -lgdi32 -lwinmm -lfreetype -ljpeg -lglu32 -lopengl32
obj\Debug gtest\MainTest.o: In function main':
D:/.../Templates/SFML 2_2 BasicScene/MainTest.cpp:5: undefined reference totesting::InitGoogleTest(int*, char**)'
obj\Debug gtest\MainTest.o: In function Z13RUN_ALL_TESTSv':
D:/.../googletest/googletest/include/gtest/gtest.h:2237: undefined reference totesting::UnitTest::GetInstance()'
D:/.../googletest/googletest/include/gtest/gtest.h:2237: undefined reference to `testing::UnitTest::Run()'
I finally found it! It was tricky: as I am using Windows 7 and installed multiple compilers (3 versions of MinGW and 2 of TDM), my PATH got all mixed up. When I was using cmake-gui 3.3, I was using the default compiler, which was MinGW 4.7 when I installed Code::Blocks. After installing all the compilers mentionned above, the default compiler path changed for a higher version of MinGW. Linking with a library that was compiled with a newer version of MinGW didn't cause the library to not be found, but instead caused linking errors.
In conclusion, I was using two differents versions of the same compiler.

Fail to use SDL with MinGW on windows

I wanted to start learning to program with SDL. So I download x86 for windows,
put all the lib and the include in MinGW. But when I compile it doesn't know the SDL functions exist.
# define SDL_MAIN_HANDLED // somehow it want it to not define its own main
#include <iostream>
#include <sdl2/SDL.h>
using namespace std;
int main( int argc, char* argv[] ) {
SDL_SetMainReady(); // just for check
return 0;
}
I read that the linking need to be in specific order (mingw32, SDL2main and then libSDL2), But I think Eclipse run a wrong compiling command.
The eclipse command:
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\fire.o" "..\\src\\fire.cpp"
g++ -o fire.exe "src\\fire.o" -lmingw32 -lSDL2main -llibSDL2
src\fire.o: In function `main':
C:\Or\C++\Projects\fire\Debug/../src/fire.cpp:16: undefined reference to `SDL_SetMainReady'
collect2.exe: error: ld returned 1 exit status
Do you think I miss something?
I think you need to change -llibSDL2 to -lSDL2.
Ok I solve it. I'm not sure if the problem was lack of support on 32 bit or the fact that minGW and SDL were from different compilers that probably didn't match..
But what I did is to delete minGW from my pc and download WinBuild. WinBuild its a download manager that offer a lot of libs and tools, include minGW64 bit and SDL.
The advantage is that they were all compile from the same compiler with the same configurations.
after that i change the path to minGW in to the new 64 bit path inside WinBuild folder, add g++ from Winbuild the to the path as well and restart.
Then, adding and linking work without any problem!
I still need to put # define SDL_MAIN_HANDLED on the start to make it work, but its work!

undefined reference to `shm_open' already with -L /lib -lrt -lpthread

I just want to use the boost library to create a shared memory on an ARM system. It work fine if you want to compile it only under ubuntu. However, when I want to cross compile it with TI's CCSv6 and angstrom toolchain, it keep pushing errors.
Because I do not know how to write a makefile for cross compile, I think using TI their own IDE might be a good choice to avoid further problems.
Here is my code and print out of build console.
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <iostream>
using namespace boost::interprocess;
int main()
{
shared_memory_object shdmem{open_or_create, "Boost1", read_write};
shdmem.truncate(1024);
mapped_region region{shdmem, read_write};
}
g++ -std=c++0x -I/usr/include -O0 -g3 -Wall -c -fmessage-length=0 -L /lib -lrt -lpthread -fPIC
The IDE called Code Composer Studio has cross compile settings as below:
Prefix: arm-angstrom-linux-gnueabi-
Path: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/armv5te-angstrom-linux-gnueabi
Build Console:
/usr/include/boost/interprocess/shared_memory_object.hpp:309: undefined reference to shm_open'
/usr/include/boost/interprocess/shared_memory_object.hpp:315: undefined reference toshm_open'
/usr/include/boost/interprocess/shared_memory_object.hpp:327: undefined reference to shm_open'
/usr/include/boost/interprocess/shared_memory_object.hpp:334: undefined reference toshm_open'
collect2: ld returned 1 exit status
make: *** [test] Error 1
undefined reference to shm_open' means it cannot find -lrt for ARM.
In your build command line you need to specify include and library paths to ARM built libraries, not to Ubuntu ones. So -I/usr/include and -L /lib is wrong.
Also you need boost built for ARM, although if you just want to use interprocess library then boost headers should be enough. But you need to copy them into different location because including them from /usr/include includes also other headers specific to Ubuntu.
You can use the cross compiler IDE you mentioned or arm g++ cross compiler which you can install by:
sudo apt-get install g++-arm-linux-gnueabihf. Some headers and libraries for ARM will be installed too.

Trouble with the compilation using libcurl on Windows XP

I downloaded the libcurl curl-7.34.0-devel-mingw32.zip from http://curl.haxx.se/gknw.net/7.34.0/dist-w32/curl-7.34.0-devel-mingw32.zip.
I use Eclipse Kepler with MinGW as the toolchain (GCC compiler). I created html.cpp and then test the code from the example http://curl.haxx.se/libcurl/c/simple.html:
I included the headers:
#include<iostream>
#include<curl/curl.h>
using namespace std;
There are 5 cURL functions. Only 2 of them (curl_easy_init,curl_easy_setopt)are said to be 'undefined reference'.
The compiler message:
Info: Internal Builder is used for build
g++ -O3 -Wall -c -fmessage-length=0 -o html.o "..\\html.cpp"
g++ -static-libgcc -static-libstdc++ -o HTML.exe html.o
html.o:html.cpp:(.text.startup+0x12): undefined reference to `_imp__curl_easy_init'
html.o:html.cpp:(.text.startup+0x1e): undefined reference to `_imp__curl_easy_setopt'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: html.o: bad reloc address 0x1e in section `.text.startup'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
The other 3 functions said to be fine:
curl_easy_perform
curl_easy_strerror
curl_easy_cleanup
I have tried to set to properties to tell the MinGW linker to include the headers and library files. The same situation as the above or the compiler simply says the .a files not found. Adding -lcurl or -DCURL_STATICLIB to the linker's flag is useless as well.
I have also tried to copy the libraries(.a files) and the headers(.h files) of libcurl to the folders bin, include and lib inside C:\MinGW and C:\gcc-4.8.1. It turns out to be no change.
Sadly, the first challenge of using cURL is not coding but the compilation. How can I solve this problem?
Thanks you guys!