I'm trying to make a PE (Portable Executable which will work with Windows XP+ and which has no dependencies.
I found this guide quite interesting http://www.catch22.net/tuts/reducing-executable-size
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
extern "C" int __cdecl __purecall(void)
{
return 0;
}
extern "C" int __cdecl main();
extern "C" int __cdecl mainCRTStartup( void )
{
int mainret;
mainret = main();
ExitProcess(mainret);
}
And I compile it with
g++ -Wall -o2 -s -nodefaultlibs main.cpp -o test.exe
And it's giving me a bunch of errors: http://i.stack.imgur.com/fIFoD.png
C:\Users\Main.cpp\Desktop\crt>g++ -Wall -o2 -s -nodefaultlibs -lkernel32 main.cpp -o test.exe
C:\Users\Main.cpp\AppData\Local\Temp\cczgOKUx.o:main.cpp:(.text+0x1c): multiple definition of `mainCRTStartup'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x280): first defined here
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x5): undefined reference to `__dyn_tls_init_callback'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x39): undefined reference to `__cpu_features_init'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x3e): undefined reference to `_fpreset'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x4b): undefined reference to `_CRT_glob'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x73): undefined reference to `__getmainargs'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x78): undefined reference to `_CRT_fmode'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x82): undefined reference to `_imp___iob'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x87): undefined reference to `_fmode'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x96): undefined reference to `_setmode'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x9b): undefined reference to `_CRT_fmode'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0xaa): undefined reference to `_setmode'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0xaf): undefined reference to `_CRT_fmode'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0xbe): undefined reference to `_setmode'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0xc3): undefined reference to `__p__fmode'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0xc9): undefined reference to `_fmode'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0xd0): undefined reference to `_pei386_runtime_relocator'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0xd8): undefined reference to `__main'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0xdd): undefined reference to `__p__environ'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x100): undefined reference to `_cexit'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x13f): undefined reference to `signal'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x195): undefined reference to `signal'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x1d0): undefined reference to `signal'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x217): undefined reference to `signal'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x233): undefined reference to `signal'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x250): more undefined references to `signal' follow
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x266): undefined reference to `_fpreset'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x28c): undefined reference to `_imp____set_app_type'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x2ac): undefined reference to `_imp____set_app_type'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x2c1): undefined reference to `_imp__atexit'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o:crt1.c:(.text+0x2d1): undefined reference to `_imp___onexit'
C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../../mingw32/bin/ld.exe: C:/TDM-GCC-32/bin/../lib/gcc/mingw32/5.1.0/../../../crt2.o: bad reloc address 0x20 in section `.eh_frame'
collect2.exe: error: ld returned 1 exit status
As far as I understood, my mainCRTStartup is interfering with another mainCRTStartup which my compiler is adding.
I'm using TDM-GCC on Windows.
After the suggestion to use -nostdlib instead of -nodefaultlibs I'm getting much less errors.
The ones I currently have are
C:\Users\Main.cpp\AppData\Local\Temp\ccMYa3VN.o:main.cpp:(.text+0x11): undefined reference to `__main'
C:\Users\Main.cpp\AppData\Local\Temp\ccMYa3VN.o:main.cpp:(.text+0x31): undefined reference to `ExitProcess#4'
GCC use some internal subroutines, contained in libgcc.a, that cannot be excluded.
See https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Link-Options.html#Link-Options:
One of the standard libraries bypassed by -nostdlib and -nodefaultlibs
is libgcc.a, a library of internal subroutines which GCC uses to
overcome shortcomings of particular machines, or special needs for
some languages. (See Interfacing to GCC Output, for more discussion of
libgcc.a.) In most cases, you need libgcc.a even when you want to
avoid other standard libraries. In other words, when you specify
-nostdlib or -nodefaultlibs you should usually specify -lgcc as well. This ensures that you have no unresolved references to internal GCC
library subroutines.
P.S. The functions ExitProcess and SetUnhandledExceptionFilter are from kernel32.lib that you must include in linker stream. You can reduce libraries, but can't omit system and OS libraries.
Related
I have some project done on C++ and I need to compile it for Windows XP and later.
This is the header file of my RsaEncryptor class (I think it is no matter to post sources here, because I'm sure on 100% that it works fine, but if it is required I can do it):
#ifndef RSAENCRYPTOR_H_
#define RSAENCRYPTOR_H_
#include <stdexcept>
#include <openssl/rsa.h>
#include <openssl/engine.h>
#include <openssl/pem.h>
// One of this paddings can be used
//#define PADDING RSA_PKCS1_OAEP_PADDING
#define PADDING RSA_PKCS1_PADDING
//#define PADDING RSA_NO_PADDING
class RsaEncryptor {
private:
RSA* publicKey;
RSA* privateKey;
public:
RsaEncryptor() {
publicKey = nullptr;
privateKey = nullptr;
}
~RsaEncryptor() {
if ( this->publicKey )
RSA_free( this->publicKey );
if ( this->privateKey )
RSA_free( this->privateKey );
}
size_t GetCipherBytesCount() {
return 172; //is default for 1024 bit key length
}
void SetPublicKeyFromString(const std::string& content);
void SetPrivateKeyFromString(const std::string& content);
std::string Encrypt(const std::string& plainData);
std::string Decrypt(const std::string& cipherData);
};
#endif /* RSAENCRYPTOR_H_ */
I use latest version of Eclipse Neon for C++ development on Windows 10 x64 machine.
Also I have read this:
(...) you will need to configure with no-async when building OpenSSL 1.1.0 and above for Windows XP or Vista
And I was guided by following instructions.
What did I do:
install Ubuntu 17.04 x64 inside Virtual Box under Windows 10 x64.
download latest version of OpenSSL library from Ubuntu
install mxe and all requirements (but can't compile with it and I decide to use mingw32)
install mingw32 via root#user-pc:/home/user# apt-get install gcc-mingw-w64-i686
unpack OpenSSL library in /home/user/openssl-x32
go to /home/user/openssl-x32
run ./Configure mingw --cross-compile-prefix=i686-w64-mingw32 --prefix=/home/user/builds/openssl-x32-static no-shared no-async
run make
run make install
copy libssl.a and libcrypto.a from /home/user/builds/openssl-x32-static/lib to host machine (Windows 10 x64) to folder E:\MyProjects\my-app\libraries\
copy include directory from Ubuntu to host machine in folder E:\MyProjects\my-app\include
Add libraries folder to linker configurations
Add include folder to compiler configurations
Then, I build my project and got following answer:
11:58:09 **** Rebuild of configuration Debug for project app ****
Info: Configuration "Debug" uses tool-chain "MinGW GCC" that is
unsupported on this system, attempting to build anyway. Info: Internal
Builder is used for build g++
"-IC:\MyProjects\my-app\include" -O0 -g3
-Wall -c -std=c++11 -m32 -o RsaEncryptor.o "..\RsaEncryptor.cpp" g++ "-IC:\MyProjects\my-app\include" -O0 -g3
-Wall -c -std=c++11 -m32 -o main.o "..\main.cpp" In file included from ..\main.cpp:5:0: ..\FilesFinder.h: In member function 'void
FilesFinder::FindRecursively(const string&, const FilesFilter&)':
..\FilesFinder.h:90:56: warning: comparison between signed and
unsigned integer expressions [-Wsign-compare]
while (destinationContainer.GetElementsCount() >= MAX_ELEMENTS_COUNT) {
^ g++ "-IC:\MyProjects\my-app\include" -O0 -g3
-Wall -c -std=c++11 -m32 -o aes256.o "..\aes256.cpp" g++ "-LC:\MyProjects\my-app\libraries"
-static-libgcc -static-libstdc++ -static -lpthread -m32 -o C:/MyProjects/my-app/bin/Debug/app
RsaEncryptor.o aes256.o main.o -lssl -lcrypto -lgdi32
C:\MyProjects\my-app\libraries\libcrypto.a(b_addr.o):b_addr.c:(.text+0xaa):
undefined reference to _imp__getnameinfo#28'
C:\MyProjects\my-app\libraries\libcrypto.a(b_addr.o):b_addr.c:(.text+0xe0):
undefined reference to_imp__ntohs#4'
C:\MyProjects\my-app\libraries\libcrypto.a(b_addr.o):b_addr.c:(.text+0x242):
undefined reference to gai_strerrorW'
C:\MyProjects\my-app\libraries\libcrypto.a(b_addr.o):b_addr.c:(.text+0x820):
undefined reference to_imp__freeaddrinfo#4'
C:\MyProjects\my-app\libraries\libcrypto.a(b_addr.o):b_addr.c:(.text+0xb5d):
undefined reference to _imp__getaddrinfo#16'
C:\MyProjects\my-app\libraries\libcrypto.a(b_addr.o):b_addr.c:(.text+0xba2):
undefined reference togai_strerrorW'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0xd7):
undefined reference to _imp__WSAStartup#8'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0xe8):
undefined reference to_imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x2c7):
undefined reference to _imp__WSAStartup#8'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x2d8):
undefined reference to_imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x3b1):
undefined reference to _imp__ntohs#4'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x40c):
undefined reference to_imp__getsockopt#20'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x423):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x43c):
undefined reference to_imp__gethostbyname#4'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x48b):
undefined reference to _imp__WSAStartup#8'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x4a2):
undefined reference to_imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x52c):
undefined reference to _imp__WSACleanup#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x54d):
undefined reference to_imp__ioctlsocket#12'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x563):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x6b7):
undefined reference to_imp__WSAStartup#8'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x6c8):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x942):
undefined reference to_imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0x9dc):
undefined reference to _imp__setsockopt#20'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0xa15):
undefined reference to_imp__ioctlsocket#12'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0xa32):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0xaa6):
undefined reference to_imp__getsockname#12'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock.o):b_sock.c:(.text+0xb22):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x27):
undefined reference to_imp__socket#12'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x4e):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x120):
undefined reference to_imp__setsockopt#20'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x15b):
undefined reference to _imp__connect#12'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x1f5):
undefined reference to_imp__setsockopt#20'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x206):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x265):
undefined reference to_imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x2c6):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x377):
undefined reference to_imp__getsockopt#20'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x38f):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x4a7):
undefined reference to_imp__setsockopt#20'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x4b4):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x53a):
undefined reference to_imp__bind#12'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x55f):
undefined reference to _imp__listen#8'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x5a5):
undefined reference to_imp__setsockopt#20'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x5b6):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x63a):
undefined reference to_imp__setsockopt#20'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x64b):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x6b2):
undefined reference to_imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x713):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x7a6):
undefined reference to_imp__accept#12'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x7e7):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x84b):
undefined reference to_imp__closesocket#4'
C:\MyProjects\my-app\libraries\libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x86c):
undefined reference to _imp__closesocket#4'
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x1b1):
undefined reference to_imp__WSASetLastError#4'
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x1d0):
undefined reference to _imp__send#16'
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x20a):
undefined reference to_imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x272):
undefined reference to _imp__WSASetLastError#4'
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x299):
undefined reference to_imp__send#16'
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x2ca):
undefined reference to _imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x33d):
undefined reference to_imp__WSASetLastError#4'
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x360):
undefined reference to _imp__recv#16'
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x39a):
undefined reference to_imp__WSAGetLastError#0'
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x457):
undefined reference to _imp__WSAGetLastError#0'
c:/programs/mingw_w64_mingw32_gcc_stdthread_win32/bin/../lib/gcc/i686-w64-mingw32/4.8.1/../../../../i686-w64-mingw32/bin/ld.exe:
C:\MyProjects\my-app\libraries\libcrypto.a(bss_sock.o):
bad reloc address 0x24 in section.rdata'
c:/programs/mingw_w64_mingw32_gcc_stdthread_win32/bin/../lib/gcc/i686-w64-mingw32/4.8.1/../../../../i686-w64-mingw32/bin/ld.exe:
final link failed: Invalid operation collect2.exe: error: ld returned
1 exit status
11:58:21 Build Finished (took 11s.567ms)
I need just link my completed C++ project with correct-compiled (with flag no-async) OpenSSL library to let it work under old versions of Windows.
I will be happy to get any help with this issue.
Most if not all of the undefined symbols in your error log come from Winsock. Try linking with -lws2_32.
I've been trying to compile this OpenGL tutorial (originally purposed for Visual Studio) but I keep having 'undefined reference' errors. The compiler output is as follows:
Info: Internal Builder is used for build
g++ -o OpenGLTutorial.exe "src\\main.o" "src\\Camera.o" -lglew32 -lglu32 -lopengl32 -lfreeglut
src\main.o: In function `Z6InitGLiPPc':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:75: undefined reference to `glutInit'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:76: undefined reference to `glutSetOption'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:77: undefined reference to `glutGet'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:78: undefined reference to `glutGet'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:80: undefined reference to `glutInitDisplayMode'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:82: undefined reference to `glutInitContextVersion'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:83: undefined reference to `glutInitContextProfile'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:84: undefined reference to `glutInitContextFlags'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:86: undefined reference to `glutInitWindowPosition'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:87: undefined reference to `glutInitWindowSize'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:89: undefined reference to `glutCreateWindow'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:91: undefined reference to `glutIdleFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:92: undefined reference to `glutDisplayFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:93: undefined reference to `glutKeyboardFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:94: undefined reference to `glutKeyboardUpFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:95: undefined reference to `glutSpecialFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:96: undefined reference to `glutSpecialUpFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:97: undefined reference to `glutMouseFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:98: undefined reference to `glutMotionFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:99: undefined reference to `glutReshapeFunc'
src\main.o: In function `main':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:236: undefined reference to `glutMainLoop'
src\main.o: In function `Z9ReshapeGLii':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:249: undefined reference to `glutPostRedisplay'
src\main.o: In function `Z9DisplayGLv':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:262: undefined reference to `glutSwapBuffers'
src\main.o: In function `Z6IdleGLv':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:278: undefined reference to `glutPostRedisplay'
src\main.o: In function `Z10KeyboardGLhii':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:313: undefined reference to `glutLeaveMainLoop'
collect2.exe: error: ld returned 1 exit status
21:39:05 Build Finished (took 1s.154ms)
Can anyone tell me what is wrong?
If you need any more information to help answer the question just ask.
Edit (Some additional info):
As you can see from the compiler output I have linked the library that these functions require and the compiler does not complain that it could not find said library. Also I placed the freeglut dll into the binary folder.
This problem was apparently mainly due to user error and was completely circumstantial. I'm posting this for the people of the future who might have this problem.
In my header file I defined FREEGLUT_STATIC. After changing this to another variable, the linker no longer produced errors. Though I can't actually check -- very easily at least -- somewhere in my freeglut library this variable was used in an ifndef statement to determine whether freeglut needed to be linked (in case it was already linked).
I have been trying to compile a windows 64 program, MSVAR1.3, on linux and have had problems with Linux and the headers that the program calls. The program calls for:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#ifdef __BORLANDC__
#include <float.h>
If I run the compile (using gcc in linux) and try to use the -I flag to tell it where the headers are, it doesn't get any better than if I run the compilation without headers at all. I have included some of the output below (I get almost 300 lines of unrecognized variables).
I have also tried running it with an -lm flag for the math library and this reduces the unrecognized errors, but if there are flags relating to libraries for the other headers, I haven't been able to find them. PLEASE HELP!!!!
(Errors from running using the -I flag:)
gcc msvar1.3.c -o msvar1.3 -lm/tmp/ccpZIkC1.o: In function `main':
msvar1.3.c:(.text+0x38): undefined reference to `opengfsr'
msvar1.3.c:(.text+0x927): undefined reference to `gfsr8'
msvar1.3.c:(.text+0x94c): undefined reference to `gfsr8'
msvar1.3.c:(.text+0x971): undefined reference to `gfsr8'
msvar1.3.c:(.text+0x9a2): undefined reference to `disrand'
msvar1.3.c:(.text+0x111a): undefined reference to `printerr'
msvar1.3.c:(.text+0x1809): undefined reference to `printerr'
msvar1.3.c:(.text+0x1ad2): undefined reference to `printerr'
msvar1.3.c:(.text+0x1be6): undefined reference to `gfsr8'
msvar1.3.c:(.text+0x2773): undefined reference to `closegfsr'
msvar1.3.c:(.text+0x2791): undefined reference to `closegfsr'
/tmp/ccpZIkC1.o: In function `treesummary':
msvar1.3.c:(.text+0x2808): undefined reference to `printerr'
/tmp/ccpZIkC1.o: In function `read_params':
msvar1.3.c:(.text+0x2b1f): undefined reference to `printerr'
msvar1.3.c:(.text+0x2b64): undefined reference to `printerr'
msvar1.3.c:(.text+0x2b72): undefined reference to `intrand'
msvar1.3.c:(.text+0x2bb7): undefined reference to `printerr'
msvar1.3.c:(.text+0x3000): undefined reference to `printerr'
msvar1.3.c:(.text+0x3063): undefined reference to `printerr'
msvar1.3.c:(.text+0x3077): undefined reference to `printerr'
/tmp/ccpZIkC1.o: In function `choosepar':
msvar1.3.c:(.text+0x36fb): undefined reference to `gfsr8'
msvar1.3.c:(.text+0x374b): undefined reference to `gfsr4'
msvar1.3.c:(.text+0x3799): undefined reference to `gfsr4'
msvar1.3.c:(.text+0x37b8): undefined reference to `norm4'
msvar1.3.c:(.text+0x37e5): undefined reference to `gfsr4'
msvar1.3.c:(.text+0x3826): undefined reference to `norm4'
msvar1.3.c:(.text+0x3853): undefined reference to `gfsr4'
msvar1.3.c:(.text+0x3894): undefined reference to `norm4'
msvar1.3.c:(.text+0x38f7): undefined reference to `norm4'
"undefined reference" errors are not from missing headers - they're linker errors indicating you don't link with an object, nor have a -l (minus ell) flag specifying a library, that exports these symbols. The headers only constitute a promise that variables and out-of-lines function matching the header declarations will be found in an object/library you provide at link time - you're breaking that promise.
You need to either find the libraries containing those symbols, or find the source and compile them.
I compiled msvar1.3 with command:
gcc -o msvar1.3 myutil.c msvar1.3.c -lm
I'm trying to build a little utility program that relies upon GraphicsMagick C++ library but I got the following error when linking to the library:
make all-recursive
make[1]: Entering directory `/home/ale/sample'
Making all in src
make[2]: Entering directory `/home/ale/sample/src'
g++ -g -O2 -o mysample mysample-a.o -L/usr/local/lib -lexiv2 -L/usr/local/lib -lGraphicsMagick++ -lGraphicsMagick
/usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o): In function `png_put_data':
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1171: undefined reference to `png_get_io_ptr'
/usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o): In function `PNGWarningHandler':
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1357: undefined reference to `png_error'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1361: undefined reference to `png_get_error_ptr'
/usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o): In function `PNGErrorHandler':
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1338: undefined reference to `png_get_error_ptr'
/usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o): In function `png_get_data':
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1060: undefined reference to `png_get_io_ptr'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1076: undefined reference to `png_warning'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1077: undefined reference to `png_error'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1067: undefined reference to `png_warning'
/usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o): In function `png_write_raw_profile':
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6243: undefined reference to `png_malloc'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6253: undefined reference to `png_malloc'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6254: undefined reference to `png_malloc'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6281: undefined reference to `png_set_text'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6282: undefined reference to `png_free'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6283: undefined reference to `png_free'
Why does the library in /usr/local/lib refers to GraphicsMagick source code (that I've built and installed)?
Errors says that you need to link with libpng too.
You having very descriptive source-code related errors because you've built graphicsmagick with debugging symbols. In release build (or if you'll strip debugging symbols out of debug build) you'll see only undefined function names, without source code references of where they're being used.
I need to call some methods from a C++ program in a C program.
But I just have one shared library (.dll) to use those methods.
To make it, first a create a wrapper in C to call the methods from the dll to be used in the C program. I have attention and I make sure that I declare the functions with extern "C" to avoid name mangling.
But when a compile I have a set of errors (shown in down) when a linking wall the .o's:
g++ -o bonnie++ bonnie++.o bon_io.o bon_file.o bon_time.o semaphore.o sync.o thread.o bon_suid.o duration.o rand.o util.o utils.o super.o pcm_file.o inode.o iname.o dir.o pcm.o -lpthread -L./ -lSmart
pcm.o:pcm.c:(.text+0x4d): undefined reference to `_imp___ZN10Management11OpenEm'
pcm.o:pcm.c:(.text+0x64): undefined reference to `_imp___ZN10Management12CloseEm'
pcm.o:pcm.c:(.text+0x73): undefined reference to `_imp___ZN10Management17EnumerateEv'
pcm.o:pcm.c:(.text+0xb9): undefined reference to `_imp___ZN18DemonstratorDevC1Ev'
pcm.o:pcm.c:(.text+0xf7): undefined reference to `_imp___ZN18DemonstratorDevD1Ev'
pcm.o:pcm.c:(.text+0x121): undefined reference to `_imp___ZN18DemonstratorDevice11OpenEi'
pcm.o:pcm.c:(.text+0x138): undefined reference to `_imp___ZN18DemonstratorDev12CloseAdapterEv'
pcm.o:pcm.c:(.text+0x15f): undefined reference to `_imp___ZN18DemonstratorDev23ConfigureClockFrequencyEi15_ClockFrequency'
pcm.o:pcm.c:(.text+0x176): undefined reference to `_imp___ZN18DemonstratorDev21AdaptationBlockEnableEv'
pcm.o:pcm.c:(.text+0x1a1): undefined reference to `_imp___ZN18CommandsManagementC1ER18DemonstratorDev'
pcm.o:pcm.c:(.text+0x1df): undefined reference to `_imp___ZN18CommandsManagementD1Ev'
pcm.o:pcm.c:(.text+0x21a): undefined reference to `_imp___ZN18CommandsManagement20DeviceInitializationEim9TimerCtrl'
pcm.o:pcm.c:(.text+0x253): undefined reference to `_imp___ZN18CommandsManagement24EnableEmbeddedOperationsER8OWStatusim9TimerCtrl'
pcm.o:pcm.c:(.text+0x290): undefined reference to `_imp___ZN18CommandsManagement12RegionUnlockEmmim9TimerCtrl'
pcm.o:pcm.c:(.text+0x2da): undefined reference to `_imp___ZN18CommandsManagement17BufferedOverwriteEmmPKhiiim9TimerCtrl'
pcm.o:pcm.c:(.text+0x32c): undefined reference to `_imp___ZN18CommandsManagement9BurstReadEmPtmih9BurstTypeim9TimerCtrl'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/bin/ld: pcm.o: bad reloc address 0x20 in section `.eh_frame$_ZN10ManagementC1Ev'
collect2: error: ld returned 1 exit status
Makefile:37: recipe for target `bonnie++' failed
make: *** [bonnie++] Error 1
Someone know what I am doing wrong?
Do you include the extern "C" function declaration header files in your wrapper method source file? if not, this error will occur