I'm running win 7 in virtual machine in my mac (parallels).
I wrote some small code and I try to run it and I get this problem:
C:\Users\Administrator\Documents\Visual Studio 10\Projects\test\Debug\test.exe : fatal error LNK1120: 1 unresolved externals
It tells me that he can't find the path in the users.
I check and all the path exists.
what I can do now?!
Edit: Here's the sample code being built:
#include<glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void myinit()
{
glClearColor(0.,0.,0.,0.);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-5., 5., -5., 5);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(200, 200);
glutInitWindowPosition(100, 100);
glutCreateWindow("Black Window");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
This is not a path problem, this is a linker error.
What linker is telling you is that you need an external library to complete compilation of your code (maybe you're using some function of another library and you forgot to add them in your project parameters).
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am trying to run a very simple example on OpenGlut for my class assignment and for some reason the code is not working on my xcode. I am currently using Xcode 10 on macOS Mojave.
Following is the code:
#include <GLUT/glut.h>
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2f( -0.5, -0.5 );
glVertex2f( 0.5, -0.5 );
glVertex2f( 0.0, 0.5 );
glEnd();
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("Hello, GL");
glutDisplayFunc(render);
glutMainLoop();
return 0;
}
This is the error message:
2018-09-29 14:38:03.737378-0700 gluttest[18974:837022] MessageTracer: load_domain_whitelist_search_tree:73: Search tree file's format version number (0) is not supported
2018-09-29 14:38:03.738891-0700 gluttest[18974:837022] MessageTracer: Falling back to default whitelist
2018-09-29 14:38:03.857540-0700 gluttest[18974:837022] flock failed to lock maps file: errno = 35
2018-09-29 14:38:03.858276-0700 gluttest[18974:837022] flock failed to lock maps file: errno = 35
To make things more clear, I am adding more information about what I have already tried:
The same code is running absolutely fine on Xcode 10 in High Sierra.
I have changed destination target to macOS 10.8 in Xcode
I have made sure OpenGL and Glut framework binaries are linked to the project.
For some reason, the window isn't drawn initially whenever glutMainLoop() is called on Mojave. You can kind of work around this by calling it in the keyboard function:
void keyboard(unsigned char key, int x, int y) {
glutPostRedisplay();
}
int main(int argc, char** argv) {
// ...
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
EDIT: A better idea:
bool hasDrawn = false;
void display() {
// ...
if (!hasDrawn) {
glutPostRedisplay();
hasDrawn = true;
}
}
void main() {
glutDisplayFunc(display);
}
#include <iostream>
#include <GLUT/GLUT.h>
#include <OpenGL/OpenGL.h>
void GraphiqueAffichage() {
glClearColor(1.0, 1.0, 0.5, 0.5);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glFlush();
}
int main(int argc, const char * argv[]) {
// insert code here...
glutInitWindowPosition(10, 10);
glutInitWindowSize(480, 272);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutCreateWindow("Bonjour");
glutDisplayFunc(GraphiqueAffichage);
glutMainLoop();
return 0;
}
Hello
I am on a Mac using OS X 10.12, ans with this code, no window is displayed, is it normal ? Why ? Please help me.
The compilation is correct, no error, build successful, but no window is created !
I tried this code that works with windows but I have a Mac and it does not work, how to make it working ?
The compilation is correct, no error, build successful ...
but you get a list of errors when you run the program, right? "Successfully compiling" does not (alas) mean your code is correct.
Looking up the very first error message, it seems you forgot to call glutInit first:
int main(int argc, char * argv[]) {
glutInit(&argc, argv);
glutInitWindowPosition(10, 10);
...
(right where your code says, "insert code here"...)
man glutInit tells you why it failed as well:
glutInit will initialize the GLUT library and negotiate a session with the window system.
where "the window system" is Mac OS X.
In addition, your main is wrong. argv is not a const char * – with that const specifier, your compiler will yell at you.
With these changes, I get a nice yellow window – your glClearColor – and with the custom title "Bonjour".
You need initializer glut
glutInit(&argc, argv);
in your main.
//#include <iostream>
#include <GLUT/GLUT.h>
#include <OpenGL/OpenGL.h>
void GraphiqueAffichage() {
glClearColor(1.0, 1.0, 0.5, 0.5);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glFlush();
}
int main(int argc, const char * argv[]) {
// insert code here...
glutInit(&argc, argv);
glutInitWindowPosition(10, 10);
glutInitWindowSize(480, 272);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutCreateWindow("Bonjour");
glutDisplayFunc(GraphiqueAffichage);
glutMainLoop();
return 0;
}
I'm using Visual Studio 2013 and am new to C++. I installed GLEW and freeglut. I try to build my file "main.c", and I receive this:
1>------ Build started: Project: testGlut1, Configuration: Debug Win32 ------
1> main.c
1>main.obj : error LNK2019: unresolved external symbol __imp__glewInit#0 referenced function _Initialize
1>main.obj : error LNK2019: unresolved external symbol __imp__glewGetErrorString#4 referenced in function _Initialize
1>C:\Users\User\documents\visual studio 2013\Projects\testGlut1\Debug\testGlut1.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I read through a similar issue, however the solution didn't work for me, in fact, nothing changed. Also, I only have 2 unresolved externals whereas the aforementioned issue showed 16 unresolved externals. Why? Why are those two errors isolated as such?
The source code for my program:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#define WINDOW_TITLE_PREFIX "Chapter 1"
int CurrentWidth = 800,
CurrentHeight = 600,
WindowHandle = 0;
unsigned FrameCount = 0;
void Initialize(int, char*[]);
void InitWindow(int, char*[]);
void ResizeFunction(int, int);
void RenderFunction(void);
void TimerFunction(int);
void IdleFunction(void);
int main(int argc, char* argv[])
{
Initialize(argc, argv);
glutMainLoop();
exit(EXIT_SUCCESS);
}
void Initialize(int argc, char* argv[])
{
GLenum GlewInitResult;
InitWindow(argc, argv);
GlewInitResult = glewInit();
if (GLEW_OK != GlewInitResult) {
fprintf(
stderr,
"ERROR: %s\n",
glewGetErrorString(GlewInitResult)
);
exit(EXIT_FAILURE);
}
fprintf(
stdout,
"INFO: OpenGL Version: %s\n",
glGetString(GL_VERSION)
);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void InitWindow(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitContextVersion(4, 0);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutSetOption(
GLUT_ACTION_ON_WINDOW_CLOSE,
GLUT_ACTION_GLUTMAINLOOP_RETURNS
);
glutInitWindowSize(CurrentWidth, CurrentHeight);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);
if (WindowHandle < 1) {
fprintf(
stderr,
"ERROR: Could not create a new rendering window.\n"
);
exit(EXIT_FAILURE);
}
glutReshapeFunc(ResizeFunction);
glutDisplayFunc(RenderFunction);
glutIdleFunc(IdleFunction);
glutTimerFunc(0, TimerFunction, 0);
}
void ResizeFunction(int Width, int Height)
{
CurrentWidth = Width;
CurrentHeight = Height;
glViewport(0, 0, CurrentWidth, CurrentHeight);
}
void RenderFunction(void)
{
++FrameCount;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
glutPostRedisplay();
}
void IdleFunction(void)
{
glutPostRedisplay();
}
void TimerFunction(int Value)
{
if (0 != Value) {
char* TempString = (char*)
malloc(512 + strlen(WINDOW_TITLE_PREFIX));
sprintf(
TempString,
"%s: %d Frames Per Second # %d x %d",
WINDOW_TITLE_PREFIX,
FrameCount * 4,
CurrentWidth,
CurrentHeight
);
glutSetWindowTitle(TempString);
free(TempString);
}
FrameCount = 0;
glutTimerFunc(250, TimerFunction, 1);
}
Here are my additional dependencies:
Here is the Debug folder in MyDocuments:
There were simply incompatibilities between the OS versions of the linked files. I thought that the process was using SysWOW64 to search for the DLL files of GLUT and GLEW since my OS is Windows 64-bit. Anyway, I used the tool, Dependecy Walker 2.2, to track an previously created .exe file and learned that my OS was searching C:\Windows\System32 for the DLL files. That changed everything, annoyingly. Out of frustration in having searched for answers for over a day and a half, I went into C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86 and swapped the glew32.lib (64-bit) for glew32.lib (32-bit), and voila, I can run my program without any errors. Since I am not an expert, or even practiced in C programming, I can only say that this is a temporary solution for my problem. I'm not sure why the program searches through C:\Windows\System32 rather than C:\Windows\SysWOW64. But, I hope that this solution helps those whom have exprienced a mysterious linker error messages when trying to use GLEW, GLUT, and Microsoft Visual Studio.
I'm running into trouble setting up GLUT (3.7.6 binaries obtained from Nate Robins) on Windows 8 64bit with VS2012. The glut32.dll is copied to the SysWOW64 dir, both include and lib path are set in my project files and the libraries are set in the Linker->Input settings ("...;glut32.lib;glu32.lib;opengl32.lib;...").
My code looks like this:
#include <GL/glut.h>
void display()
{
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutDisplayFunc(display);
glutMainLoop();
}
The build process is successful but the application crashes with the following error message:
Unhandled exception at 0x1000BBAE (glut32.dll) in HelloOpenGL.exe: 0xC0000005: Access violation writing location 0x000000A8.
The setup seems fairly simple. Any ideas what I'm missing?
The call to glutDisplayFunc() without opening a window caused the crash. This is the updated code that opens a new window before passing the display function:
#include <GL/glut.h>
void display()
{
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
//Set Display Mode
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
//Set the window size
glutInitWindowSize(250,250);
//Set the window position
glutInitWindowPosition(100,100);
//Create the window
glutCreateWindow("Hello OpenGL");
//Set the display function
glutDisplayFunc(display);
//Enter the main loop
glutMainLoop();
}
So, I was reading http://ogldev.atspace.co.uk/www/tutorial02/tutorial02.html and it said I needed math_3d.h for Vector3f.
I tried to include it:
#include <stdio.h>
#include "GL/glew.h"
#include "GL/gl.h"
#include "GL/freeglut.h"
#include "math_3d.h"
void render() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("OpenGL - First window demo");
/* Set */
GLenum res = glewInit();
if (res != GLEW_OK) {
fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
return 1;
}
Vector3f vertices[1];
glutDisplayFunc(render);
glutMainLoop();
return 0;
}
G++ said "main.cpp:7:21: fatal error: math_3d.h: No such file or directory". I looked for an Arch Linux package for it, but I found nothing.
I found the file here:
http://ogldev.googlecode.com/svn-history/r75/trunk/tutorial36/math_3d.h
Am I supposed to download that file and place it my project directory, or is there a cleaner way of doing it?
Also, if I do include it in my directory, how can I add it to the g++ line?
gcc main.cpp -o main -lGLEW -lglut -lGL
Am I supposed to download that file and place it my project directory?
Yes
It's sufficient download the file in your directory. Is not required to add it to gcc command line.
Yes you have to download it, if you need this library in more than one project you can save it in /usr/include and use it as a C library with #include <math_3d.h>, avoiding to copy it in every single project's directory.