链接器错误导致GLSL演示失败:代码1失败

时间:2015-11-16 09:09:39

标签: c++ opengl linker glsl

我只是下载这个demo,创建一个cocoa项目,添加框架OpenGL,GLKit,GLUT,现在它可以编译,但是我得到了链接器错误:

clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)

有什么想法吗?

这是我添加到项目中的cpp文件(我没有对项目已有的文件做任何事情,比如ViewController。*,AppDelegate。*):

//
//  geometryFeedback.cpp
//
//
#include "stdio.h"
#include <OpenGL/gl3.h>

#include <GLUT/glut.h>
// Shader macro
#define GLSL(src) "#version 400 core\n" #src

// Vertex shader
const GLchar* vertexShaderSrc = GLSL(
                                     in float inValue;
                                     out float geoValue;

                                     void main() {
                                         geoValue = sqrt(inValue);
                                     }
                                     );

// Geometry shader
const GLchar* geoShaderSrc = GLSL(
                                  layout(points) in;
                                  layout(triangle_strip, max_vertices = 3) out;

                                  in float[] geoValue;
                                  out float outValue;

                                  void main() {
                                      for (int i = 0; i < 3; i++) {
                                          outValue = geoValue[0] + i;
                                          EmitVertex();
                                      }

                                      EndPrimitive();
                                  }
                                  );

int main() {
    // Window


    // Compile shaders
    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShader, 1, &vertexShaderSrc, nullptr);
    glCompileShader(vertexShader);

    GLuint geoShader = glCreateShader(GL_GEOMETRY_SHADER);
    glShaderSource(geoShader, 1, &geoShaderSrc, nullptr);
    glCompileShader(geoShader);

    // Create program and specify transform feedback variables
    GLuint program = glCreateProgram();
    glAttachShader(program, vertexShader);
    glAttachShader(program, geoShader);

    const GLchar* feedbackVaryings[] = { "outValue" };
    glTransformFeedbackVaryings(program, 1, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);

    glLinkProgram(program);
    glUseProgram(program);

    // Create VAO
    GLuint vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    // Create input VBO and vertex format
    GLfloat data[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };

    GLuint vbo;
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);

    GLint inputAttrib = glGetAttribLocation(program, "inValue");
    glEnableVertexAttribArray(inputAttrib);
    glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0);

    // Create transform feedback buffer
    GLuint tbo;
    glGenBuffers(1, &tbo);
    glBindBuffer(GL_ARRAY_BUFFER, tbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(data) * 3, nullptr, GL_STATIC_READ);

    // Perform feedback transform
    glEnable(GL_RASTERIZER_DISCARD);

    glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo);

    glBeginTransformFeedback(GL_TRIANGLES);
    glDrawArrays(GL_POINTS, 0, 5);
    glEndTransformFeedback();

    glDisable(GL_RASTERIZER_DISCARD);

    glFlush();

    // Fetch and print results
    GLfloat feedback[15];
    glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(feedback), feedback);

    for (int i = 0; i < 15; i++) {
        printf("%f\n", feedback[i]);
    }

    return 0;
}

链接器信息:

Ld /Users/WY/Library/Developer/Xcode/DerivedData/TransformFeedback-apcdjlohrayxsdeuvwzbzxatazbc/Build/Products/Debug/TransformFeedback.app/Contents/MacOS/TransformFeedback normal x86_64
    cd /Users/WY/Documents/3DPrinting/code/TransformFeedback
    export MACOSX_DEPLOYMENT_TARGET=10.11
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -L/Users/WY/Library/Developer/Xcode/DerivedData/TransformFeedback-apcdjlohrayxsdeuvwzbzxatazbc/Build/Products/Debug -F/Users/WY/Library/Developer/Xcode/DerivedData/TransformFeedback-apcdjlohrayxsdeuvwzbzxatazbc/Build/Products/Debug -filelist /Users/WY/Library/Developer/Xcode/DerivedData/TransformFeedback-apcdjlohrayxsdeuvwzbzxatazbc/Build/Intermediates/TransformFeedback.build/Debug/TransformFeedback.build/Objects-normal/x86_64/TransformFeedback.LinkFileList -Xlinker -rpath -Xlinker @executable_path/../Frameworks -mmacosx-version-min=10.11 -fobjc-arc -fobjc-link-runtime -stdlib=libc++ -framework GLKit -framework QTKit -framework OpenGL -framework GLUT -framework Cocoa -Xlinker -dependency_info -Xlinker 
/Users/WY/Library/Developer/Xcode/DerivedData/TransformFeedback-apcdjlohrayxsdeuvwzbzxatazbc/Build/Intermediates/TransformFeedback.build/Debug/TransformFeedback.build/Objects-normal/x86_64/TransformFeedback_dependency_info.dat -o /Users/WY/Library/Developer/Xcode/DerivedData/TransformFeedback-apcdjlohrayxsdeuvwzbzxatazbc/Build/Products/Debug/TransformFeedback.app/Contents/MacOS/TransformFeedback

duplicate symbol _main in:
    /Users/WY/Library/Developer/Xcode/DerivedData/TransformFeedback-apcdjlohrayxsdeuvwzbzxatazbc/Build/Intermediates/TransformFeedback.build/Debug/TransformFeedback.build/Objects-normal/x86_64/geometryFeedback.o
    /Users/WY/Library/Developer/Xcode/DerivedData/TransformFeedback-apcdjlohrayxsdeuvwzbzxatazbc/Build/Intermediates/TransformFeedback.build/Debug/TransformFeedback.build/Objects-normal/x86_64/main.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

0 个答案:

没有答案